Libraries: TradeAlgorithms
Regarding:
//| Trade algorithms for brokers who offer nonzero spread and | //| and stops setting after opening a position!
in your code where you setup the request to modify a Buy . . .
bool BuyPositionModify . . . //---- initializing structure of the MqlTradeRequest to open BUY position request.type = ORDER_TYPE_BUY; request.price = Ask; request.action = TRADE_ACTION_SLTP; request.symbol = symbol; //---- Determine distance to Stop Loss (in price chart units) if(StopLoss) { if(!StopCorrect(symbol,StopLoss))return(false); double dStopLoss=StopLoss*point; request.sl=NormalizeDouble(request.price-dStopLoss,digit); if(request.sl<PositionGetDouble(POSITION_SL)) request.sl=PositionGetDouble(POSITION_SL); } else request.sl=PositionGetDouble(POSITION_SL); //---- Determine distance to Take Profit (in price chart units) if(Takeprofit) { if(!StopCorrect(symbol,Takeprofit))return(false); double dTakeprofit=Takeprofit*point; request.tp=NormalizeDouble(request.price+dTakeprofit,digit); if(request.tp<PositionGetDouble(POSITION_TP)) request.tp=PositionGetDouble(POSITION_TP); } else request.tp=PositionGetDouble(POSITION_TP);
you set the type, price, action, symbol, sl and tp. The documentation states that only the action, symbol, tp and sl are required, why do you also setup type and price ? have you found that the documentation is incorrect ?
Hello friends,
Otávio, your statement is correct. It is option 1.
In my case:
Invalid data for trade request structure!
OrderCheck(): Unsupported type of order execution by balance is specified
I tried all 4 options too) The values of request.type, request.price, request.action, etc. seem to be correct.
TradeAlgorithms:
Author: Nikolay Kositsin