You haven't really given enough information
I'm guessing the Signal Buy is if it closes above what I'm assuming is a moving average but if the close signal can't happen within the next five candles it'll always buy on the first one, also if it does close you logic says re-open.. make no sense
You haven't really given enough information
I'm guessing the Signal Buy is if it closes above what I'm assuming is a moving average but if the close signal can't happen within the next five candles it'll always buy on the first one, also if it does close you logic says re-open.. make no sense
To get out of the signal I use indicator or a MACD or a Moving.
I have no problem leaving the signal
My problem is that when the indicator gives only 5 candlesticks after the first signal, you take the position.
If the indicator covers more than 10 or 20 candlesticks, only the first 5 candlesticks can be positioned.
I hope I mean.
Thank you dear friend
To get out of the signal I use indicator or a MACD or a Moving.
I have no problem leaving the signal
My problem is that when the indicator gives only 5 candlesticks after the first signal, you take the position.
If the indicator covers more than 10 or 20 candlesticks, only the first 5 candlesticks can be positioned.
I hope I mean.
So do you only take a position on the 5th candle?
then something like:
Close_1 > MovingAvg_1
Close_2 > MovingAvg_2
Close_3 > MovingAvg_3
Close_4 > MovingAvg_4
Close_5 > MovingAvg_5
Close_6 > MovingAvg_6
Open_6 < MovingAvg_6
So do you only take a position on the 5th candle?
then something like:
Close_1 > MovingAvg_1
Close_2 > MovingAvg_2
Close_3 > MovingAvg_3
Close_4 > MovingAvg_4
Close_5 > MovingAvg_5
Close_6 > MovingAvg_6
Open_6 < MovingAvg_6
double b1_shift1=iCustom(Symbol(),0,"HamaSystem",0,1); double b1_shift2=iCustom(Symbol(),0,"HamaSystem",1,1); double b2_shift1=iCustom(Symbol(),0,"HamaSystem",0,2); double b2_shift2=iCustom(Symbol(),0,"HamaSystem",1,2); if (b1_shift1<b2_shift1 && b1_shift2>b2_shift2) { if(Orders()==5) Pendbuy(); } if (b1_shift1>b2_shift1 && b1_shift2<b2_shift2) { if(Orders()==5) Pendsell(); }
With this code, when an indicator gives a position to track the signal from buy to sell, one position per candle
double b1_shift1=iCustom(Symbol(),0,"HamaSystem",0,1); double b1_shift2=iCustom(Symbol(),0,"HamaSystem",1,1); double b2_shift1=iCustom(Symbol(),0,"HamaSystem",0,2); double b2_shift2=iCustom(Symbol(),0,"HamaSystem",1,2); if (b1_shift2>b2_shift2) { if(Orders()==5) Pendbuy(); } if (b1_shift2<b2_shift2) { if(Orders()==5) Pendsell(); }
But I want to cover only the first 5 candlesticks
every time it gives a signal
Programming is very hard and hard to explain
If you understand what I mean
Can
you give me his code?
Tanks
Maybe:
if there's no open trades then open on signal
if there is an open trade loop over the trades to pick out the earliest OrderOpenTime (search OrderSelect and for loops)
then put a condition/filter to only trade if TimeCurrent < FirstOrderOpenTime + (Period converted to second) x 5
With this code, when the signal indicator starts positioning in the first candle, only 1 position
With this code, when an indicator gives a position to track the signal from buy to sell, one position per candle
But I want to cover only the first 5 candlesticks every time it gives a signal
If I understand you correctly, how about declaring two new global variables:
datetime TimeOfBuySignal = 0, TimeOfSellSignal = 0;
And when you check for signal, do this:
if (b1_shift1<b2_shift1 && b1_shift2>b2_shift2) // Based on your code { TimeOfBuySignal = iTime(Symbol(),Period(),1); TimeOfSellSignal = 0; } if (b1_shift1>b2_shift1 && b1_shift2<b2_shift2) // Based on your code { TimeOfSellSignal = iTime(Symbol(),Period(),1); TimeOfBuySignal = 0; }
Finally, do this:
if (TimeOfBuySignal>0 && iBarShift(Symbol(),Period(),TimeOfBuySignal)<=MathMax(5,Orders()) PendBuy(); if (TimeOfSellSignal>0 && iBarShift(Symbol(),Period(),TimeOfSellSignal)<=MathMax(5,Orders()) PendSell();
Of course, all these codes must execute when a new candle is formed, not every tick.
![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
Hi everyone
How can I buy only the first 5 candles of Experts when the signal is given.
Thanks everyone.