Here’s an MQL5 script that implements a simple buy and sell strategy for Toncoin (TON)
https://www.tradingview.com/pricing/?share_your_love=vancitytech
Tell your buddies
Do you love TradingView and use us to make better investing decisions? Get $15 towards the purchase of any subscription for
Here’s an MQL5 script that implements a simple buy and sell strategy for Toncoin (TON) using Relative Strength Index (RSI) and Bollinger Bands as signals.
This script:
- Buys when RSI is below 30 (oversold) and the price is near the lower Bollinger Band.
- Sells when RSI is above 70 (overbought) and the price is near the upper Bollinger Band.
//+------------------------------------------------------------------+
//| TONCOIN Trading Strategy - RSI & Bollinger Bands |
//+------------------------------------------------------------------+
#include <Trade\Trade.mqh>
CTrade trade;
//— Input parametersinput int rsiPeriod = 14; // RSI period
input int bollingerPeriod = 20; // Bollinger Bands period
input double bollingerDeviation = 2.0; // Bollinger Bands deviation
input double lotSize = 0.1; // Lot size
input int slPips = 50; // Stop Loss in pips
input int tpPips = 100; // Take Profit in pips
input ENUM_TIMEFRAMES timeframe = PERIOD_M15; // Timeframe
//+——————————————————————+
//| Main Trading Function |
//+——————————————————————+
void OnTick()
{
double rsiValue, upperBand, lowerBand, middleBand, price;
int rsiHandle, bollingerHandle;
// Get RSI value
rsiHandle = iRSI(_Symbol, timeframe, rsiPeriod, PRICE_CLOSE);
if(rsiHandle != INVALID_HANDLE)
{
rsiValue = iCustom(_Symbol, timeframe, “RSI”, rsiPeriod, PRICE_CLOSE, 0, 0);
}
// Get Bollinger Bands values
bollingerHandle = iBands(_Symbol, timeframe, bollingerPeriod, bollingerDeviation, 0, PRICE_CLOSE);
if(bollingerHandle != INVALID_HANDLE)
{
upperBand = iBands(_Symbol, timeframe, bollingerPeriod, bollingerDeviation, 0, PRICE_CLOSE, MODE_UPPER, 0);
middleBand = iBands(_Symbol, timeframe, bollingerPeriod, bollingerDeviation, 0, PRICE_CLOSE, MODE_MAIN, 0);
lowerBand = iBands(_Symbol, timeframe, bollingerPeriod, bollingerDeviation, 0, PRICE_CLOSE, MODE_LOWER, 0);
}
// Get the current price
price = SymbolInfoDouble(_Symbol, SYMBOL_BID);
// Check for BUY Signal
if(rsiValue < 30 && price <= lowerBand)
{
if(PositionSelect(_Symbol) == false)
{
trade.Buy(lotSize, _Symbol, price, price – slPips * _Point, price + tpPips * _Point);
Print(“BUY Order placed at “, price);
}
}
// Check for SELL Signal
if(rsiValue > 70 && price >= upperBand)
{
if(PositionSelect(_Symbol) == false)
{
trade.Sell(lotSize, _Symbol, price, price + slPips * _Point, price – tpPips * _Point);
Print(“SELL Order placed at “, price);
}
}
}
Explanation:
- RSI Check
- Buys when RSI < 30 (oversold).
- Sells when RSI > 70 (overbought).
- Bollinger Bands Check
- Buys when price touches the lower band.
- Sells when price touches the upper band.
- Trade Execution
- Places buy/sell orders with lot size, stop loss, and take profit settings.
- Ensures only one trade is open at a time.
Let me know if you need any modifications!
David tech gut in vancouver !
send message through whatsapp https://www.whatsapp.com/ +1-778-918-2815
We build any mql5 robot .