Thanks Sir. But whtat exactly do you mean by that?
Bar #0 cannot be used in the algorithm for finding the highest and lowest prices.
void CChannelBreakout::GetHighestHighAndLowestLow(int &BarsHigh, int &BarsLow) { //+--------------------------------------------------------------------+ //|Firstly, declare the arrays to hold the candlesticks highs and lows | //+--------------------------------------------------------------------+ double High[]; ArraySetAsSeries(High,true); CopyHigh(_Symbol,PERIOD_CURRENT,0,BarsHigh,High); double Low[]; ArraySetAsSeries(Low,true); CopyLow(_Symbol,PERIOD_CURRENT,0,BarsLow,Low); //+-------------------------------------------------------------------------------+ //|Secondly, declare the variables to hold the array numbers which is the highest | //+-------------------------------------------------------------------------------+ int HighestHighArrNo = ArrayMaximum(High,0,BarsHigh); int LowestLowArrNo = ArrayMinimum(Low,0,BarsLow); //+-----------------------------------------------------------------------------------+ //|Thirdly, declare the arrays to hold the value of the highest high and lowest lows | //|from the array number | //+-----------------------------------------------------------------------------------+ HighestHighValue = High[HighestHighArrNo]; LowestLowValue = Low[LowestLowArrNo]; }
Bar #0 cannot be used in the algorithm for finding the highest and lowest prices.
Ok thanks. But problem keeps persisting. Do you think there's any other thing I have to do?
You haven't done anything. Correct the error and show your code.
void OnTick() { double high[]; ArraySetAsSeries(high,true); CopyHigh(_Symbol,PERIOD_CURRENT,1,11,high); double Low[]; ArraySetAsSeries(Low,true); CopyLow(_Symbol,PERIOD_CURRENT,1,11,Low); int HighestHighArrNo = ArrayMaximum(high,0,10); int LowestLowArrNo = ArrayMinimum(Low,0,10); double HighestHighValue = high[HighestHighArrNo]; double LowestLowValue = Low[LowestLowArrNo]; double close[]; ArraySetAsSeries(close,true); CopyClose(_Symbol,PERIOD_CURRENT,0,1,close); if(close[0]>HighestHighValue) Print("Buy"); if(close[0]<LowestLowValue) Print("Sell");
Sir I did this, and now the EA just keeps opening positions on it own. And still the problem persisits
Sir I did this, and now the EA just keeps opening positions on it own. And still the problem persisits
The EA is now looking for the maximum (and minimum) price correctly.
While your mistake is that you do not control the number of positions (check the number of positions before checking the signal).
//+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnTick() { if(PositionsTotal()==0) { double arr_high[],arr_low[]; ArraySetAsSeries(arr_high,true); ArraySetAsSeries(arr_low,true); int start_pos=1,count=11; if(CopyHigh(Symbol(),Period(),start_pos,count,arr_high)==count && CopyLow(Symbol(),Period(),start_pos,count,arr_low)==count) { int high_max_index = ArrayMaximum(arr_high,0,WHOLE_ARRAY); int low_min_index = ArrayMinimum(arr_low,0,WHOLE_ARRAY); double highes = arr_high[high_max_index]; double lowest = arr_low[low_min_index]; //--- double arr_close[]; ArraySetAsSeries(close,true); start_pos=0,count=1; CopyClose(Symbol(),Period(),start_pos,count,arr_close); if(arr_close[0]>high_max_index) Print("Buy"); if(arr_close[0]<low_min_index) Print("Sell"); } } }
Thanks Moderator, but problem keeps persisting even after using your code, they there where some few syntax errors in the spellings, but then the program keeps placing trades as it wants to, not following the signal
If you find two mistakes - you are great :) - then you are a thinking person!
I have provided the simplest code - in order to accurately control the number of positions, you need to control the execution of trade orders.
An example of how to catch a trade transaction:
Forum on trading, automated trading systems and testing trading strategies
Vladimir Karputov, 2020.10.22 20:31
We catch the transaction
Code: We catch the transaction.mq5
This is a blank - an example of how to control a trading signal. This code avoids the situation: opening multiple positions. How it works: after a trade order is generated, we increase the 'SPosition' structure. In OnTick, if 'SPosition' is greater than zero, go to the block for opening positions. In OnTradeTransaction, we monitor the situation when a position appears exactly on our signal.

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
That's the code guys. I've been working on it now for long, I just can't find a way to get pass the placing or order section. I'd appreciate your help. Thanks