Which of these three codes is right. I'm a newbie in coding please help.
When have 2 closing price above moving average buy.
When have 2 closing price below moving average sell.
Thanks.
if(Close[1]>ma) if(Close[2]>ma) { res=OrderSend(Symbol(),OP_BUY,GetLots(),Ask,3,0,0,"",BRO,0,Blue); return; }
this will open a buy if the last bar and the bar before that are above the ma. Do you want to check if the current bar, Close[0], is above the ma too?
also, by the coding example, I think you really mean close above ma AND open below the ma?
sn
1 bar break a moving average and close above - waiting - second bar close above ma - and open long position.
Terms is to buy when have 2 closing price above ma.
First bar open below and close above ma. Second bar open above him and close above ma.
I want two closing bars above, i don't give a ... for opens.
Is it right that below i posted.
Thanks a lot.
void CheckForOpen() { double ma; int res; //----go trading only first tiks of new Bars if(Volume[0]>1 return; //----get Moving Average ma=iMA(NULL,0,MovingPeriod,0,MODE_SMA,PRICE_CLOSE,0); //----sell conditions if(Close[1]<ma) if(Close[2]<ma) { res=OrderSend(Symbol(),OP_SELL,GetLots(),Bid,3,0,0,"Good luck",MAGICMA,0,Magenta); return; } //----buy conditions if(Close[1]>ma) if(Close[2]>ma) { res=OrderSend(Symbol(),OP_BUY,GetLots(),Ask,3,0,0,"Good luck",MAGICMA,0,Aqua); return; } }
if(Volume[0]>1 return;
Volume is unreliable, Bars is unreliable. Always use time.int start(){ static datetime Time0; if (Time0 == Time[0]) return; Time0 = Time[0];
if(Open[1]>ma && Close[1]<ma) continue;
This won't even compile, you're not in a loop.
if(Open[1]>ma && Close[1]<ma) - that must be check. How to continue to check second closing price and after check it - to do action.
if(Open[2]<ma && Close[2]<ma) that is for sell conditions. Thanks a lot
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use