When you post code please use the Code button (Alt+S) !
...
Improperly formatted code removed by moderator. Please EDIT your post and use the CODE button (Alt-S) when inserting code.
Hover your mouse over your post and select "edit" ...
...
- www.mql5.com
//+------------------------------------------------------------------+ //| Search trading signals | //+------------------------------------------------------------------+ bool SearchTradingSignals(ENUM_ORDER_TYPE type = WRONG_VALUE) { //if(iTime(m_symbol.Name(),InpWorkingPeriod,0)==m_last_deal_in) // on one bar - only one deal // return(true); int size_need_position=ArraySize(SPosition); if(size_need_position>0) return(true); int size_need_pending=ArraySize(SPending); int count_buys; int count_sells; CalculateAllPositions(count_buys,count_sells); if(InpMaxPositions!=0&&count_buys+count_sells>=InpMaxPositions) return(true); //--- open a sell if there is no open position if(count_buys+count_sells==0) { ArrayResize(SPosition,size_need_position+1); SPosition[size_need_position].pos_type=POSITION_TYPE_SELL; if(InpPrintLog) Print(__FILE__," ",__FUNCTION__,", OK: ","Signal SELL"); ArrayResize(SPending,size_need_pending+1); SPending[size_need_pending].pending_type=ORDER_TYPE_BUY_STOP; SPending[size_need_pending].volume=InpVolumeHedge; if(InpPrintLog) Print(__FILE__," ",__FUNCTION__,", OK: ","Signal BUY STOP"); return(true); } if(type==ORDER_TYPE_BUY_STOP && !m_pause_buy) { ArrayResize(SPending,size_need_pending+1); SPending[size_need_pending].pending_type=ORDER_TYPE_BUY_STOP; SPending[size_need_pending].volume= GetMartinLot(InpVolumeHedge,count_buys+count_sells); if(InpPrintLog) Print(__FILE__," ",__FUNCTION__,", OK: ","Signal BUY STOP"); return(true); } //if(count_buys==1&&count_sells==1&&spike_open_price==0.0) // spike_open_price= iOpen(m_symbol.Name(),Period(),0); if(type==ORDER_TYPE_SELL_STOP && !m_pause_sell) { ArrayResize(SPending,size_need_pending+1); SPending[size_need_pending].pending_type=ORDER_TYPE_SELL_STOP; SPending[size_need_pending].volume= GetMartinLot(InpVolumeHedge,count_sells+count_buys); SPending[size_need_pending].price= m_last_deal_price_b-(m_last_deal_price_b-m_last_deal_price_s)/InpPendingIndentRatio; if(InpPrintLog) Print(__FILE__," ",__FUNCTION__,", OK: ","Signal SELL STOP"); return(true); } //--- return(true); }
this is not the chatgpt code but it is part of the code of my robot created by a developer here on mql5 but currently it is no longer reachable on telephone
then I want the robot to add a single pending position, this is fine in the strategy tester but on a demo account it opens more than two pending positions.
//+------------------------------------------------------------------+ //| Search trading signals | //+------------------------------------------------------------------+ bool SearchTradingSignals(ENUM_ORDER_TYPE type = WRONG_VALUE) { //if(iTime(m_symbol.Name(),InpWorkingPeriod,0)==m_last_deal_in) // on one bar - only one deal // return(true); int size_need_position=ArraySize(SPosition); if(size_need_position>0) return(true); int size_need_pending=ArraySize(SPending); int count_buys; int count_sells; CalculateAllPositions(count_buys,count_sells); if(InpMaxPositions!=0&&count_buys+count_sells>=InpMaxPositions) return(true); //--- open a sell if there is no open position if(count_buys+count_sells==0) { ArrayResize(SPosition,size_need_position+1); SPosition[size_need_position].pos_type=POSITION_TYPE_SELL; if(InpPrintLog) Print(__FILE__," ",__FUNCTION__,", OK: ","Signal SELL"); ArrayResize(SPending,size_need_pending+1); SPending[size_need_pending].pending_type=ORDER_TYPE_BUY_STOP; SPending[size_need_pending].volume=InpVolumeHedge; if(InpPrintLog) Print(__FILE__," ",__FUNCTION__,", OK: ","Signal BUY STOP"); return(true); } if(type==ORDER_TYPE_BUY_STOP && !m_pause_buy) { if(size_need_pending<1) { ArrayResize(SPending,size_need_pending+1); SPending[size_need_pending].pending_type=ORDER_TYPE_BUY_STOP; SPending[size_need_pending].volume= GetMartinLot(InpVolumeHedge,count_buys+count_sells); if(InpPrintLog) Print(__FILE__," ",__FUNCTION__,", OK: ","Signal BUY STOP"); return(true); } } //if(count_buys==1&&count_sells==1&&spike_open_price==0.0) // spike_open_price= iOpen(m_symbol.Name(),Period(),0); if(type==ORDER_TYPE_SELL_STOP && !m_pause_sell) { { if(size_need_pending<1) ArrayResize(SPending,size_need_pending+1); SPending[size_need_pending].pending_type=ORDER_TYPE_SELL_STOP; SPending[size_need_pending].volume= GetMartinLot(InpVolumeHedge,count_sells+count_buys); SPending[size_need_pending].price= m_last_deal_price_b-(m_last_deal_price_b-m_last_deal_price_s)/InpPendingIndentRatio; if(InpPrintLog) Print(__FILE__," ",__FUNCTION__,", OK: ","Signal SELL STOP"); return(true); } } //--- return(true); }
If you are not a coder then you will probably not be able to understand any advice given to you, nor are we going to code it for you.
You have only provided a small part of the code and it may not even be relevant within the context of the entire program.
So, I suggest you hire another coder to make the necessary changes 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 want to have a code to allow only one position waiting for my code