I've created an EA for 30Min chart which is supposed to open trades base on RSI values and Donchian Channel. I guess the problem is with "iCustom" function calling, cause it doesn't print the indicator when I back test it.
I appreciate if someone kindly debug this code for me.
Below are trading criteria:
BUY:
If Donchian Channel Low is already touched (Buy trade is permitted), then whenever RSI moves above 30, I should have a buy trade. Take profit level is either 300 PIP or when the Donchain Channel Upper is touched.
SELL:
If Donchian Channel Upper is already touched (Sell trade is permitted), then whenever RSI moves below 70, I should have a sell trade. Take profit level is either 300 PIP or when the Donchain Channel Low is touched.
Below is the code:
Also, below is the code for Donchian Channel Indicator created by RasoulFX (FYI):
Check out the Freelance section, it's awesome if you want something done!
- www.mql5.com
There are several issues that need to fixed:
- prevTime gets updated only when orders are opened, do you want checks on every tick or on new bar
- the signals are being reset on every
tick so the buy/sell flag is lost when RSI crosses the threshold
- the exit for loop traverses orders front to back, so when closing an order you miss out the next one
- you open order with an invalid TP (TakeProfit)
- some checks should be moved to OnInit
- shift on iCustom call should be 1, not 0, if you run it at new bar time
- if you want to check RSI on every tick, RSICurrent shift should be 0
- RSIPrev should be the previous RSICurrent, not the one from 30+ minutes ago
- you are not checking if any order matches its magic number
There are several issues that need to fixed:
- prevTime gets updated only when orders are opened, do you want checks on every tick or on new bar
- the signals are being reset on every
tick so the buy/sell flag is lost when RSI crosses the threshold
- the exit for loop traverses orders front to back, so when closing an order you miss out the next one
- you open order with an invalid TP (TakeProfit)
- some checks should be moved to OnInit
- shift on iCustom call should be 1, not 0, if you run it at new bar time
- if you want to check RSI on every tick, RSICurrent shift should be 0
- RSIPrev should be the previous RSICurrent, not the one from 30+ minutes ago
- you are not checking if any order matches its magic number
I tried my best to incorporate your comments into my EA, but since I'm a very novice programmer, all my effort took me nowhere, my EA became worse by every try, full of errors. So I highly appreciate if you can kindly debug my EA for me.
From reading your code it is unclear if you intend to check open conditions on every tick or on new bar only.
New bar only.
Please see picture below/attached picture:
New bar only.
In this case you need to fix your new bar check first before going on:
static datetime prevTime; if(Time[0]!=prevTime) // if(total<1) { //--- no opened orders identified if(AccountFreeMargin()<(1000*Lots)) { Print("We have no money. Free Margin = ",AccountFreeMargin()); return; } //--- check for long position (BUY) possibility if(iLow(Symbol(),Period(),1)==DonchianLow) {BuySignal=true; SellSignal=false;} if(BuySignal=true && RSICurrent>30 && RSIPrev<30) { ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,0,TakeProfit,"TP",17384,0,Green); if(ticket>0) { if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) { Print("BUY order opened : ",OrderOpenPrice()); prevTime=Time[0]; ticket=OrderModify(OrderTicket(),OrderOpenPrice(),Bid-StopLoss*Point,TakeProfit,0,Yellow); } } else Print("Error opening BUY order : ",GetLastError()); return; } //--- check for short position (SELL) possibility if(iHigh(Symbol(),Period(),1)==DonchianUP) {BuySignal=false; SellSignal=true;} if(SellSignal=true && RSICurrent<70 && RSIPrev>70) { ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,0,TakeProfit,"TP",17384,0,Red); if(ticket>0) { if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) { Print("SELL order opened : ",OrderOpenPrice()); prevTime=Time[0];
A new bar check should work like this:
static datetime prevTime=0; if(Time[0]!=prevTime) { // we got a new bar prevTime=Time[0]; // action goes here }
Now that you've been provided with a lengthy list of issues to be fixed. Why not take this thread as job description and have that EA coded for you?
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
I've created an EA for 30Min chart which is supposed to open trades base on RSI values and Donchian Channel. I guess the problem is with "iCustom" function calling, cause it doesn't print the indicator when I back test it.
I appreciate if someone kindly debug this code for me.
Below are trading criteria:
BUY:
If Donchian Channel Low is already touched (Buy trade is permitted), then whenever RSI moves above 30, I should have a buy trade. Take profit level is either 300 PIP or when the Donchain Channel Upper is touched.
SELL:
If Donchian Channel Upper is already touched (Sell trade is permitted), then whenever RSI moves below 70, I should have a sell trade. Take profit level is either 300 PIP or when the Donchain Channel Low is touched.
Below is the code:
Also, below is the code for Donchian Channel Indicator created by RasoulFX (FYI):