ストップロスの設定がエントリー時に設定されていること
OrderModify が失敗したら二度とSL, TPが設定されないためNG(決済がSL, TP のみ行われているロジックの場合)
if( EntryPosition == 1 ) //買いの場合のエントリ条件
{
res=OrderSend(Symbol(),OP_BUY,Lots ,Ask,SLP,0,0,"TrendLogic",MAGIC,0,Red);
if (OrderSelect(res,SELECT_BY_TICKET)==true)
{
if (Buy_stoploss!=0) SL=OrderOpenPrice()-Buy_stoploss*AdjustPoint(Symbol());
if (Buy_takeprofit!=0) TP=OrderOpenPrice()+Buy_takeprofit*AdjustPoint(Symbol());
}
Modified=OrderModify(OrderTicket(),OrderOpenPrice(),SL,TP,0,Red);
}
else if(EntryPosition == -1 ) //---- 売りエントリ
{
res=OrderSend(Symbol(),OP_SELL,Lots,Bid,SLP,0,0,"TrendLogic",MAGIC,0,White);
if(OrderSelect(res,SELECT_BY_TICKET)==true)
{
if(Sell_stoploss!=0) SL=OrderOpenPrice()+Sell_stoploss*AdjustPoint(Symbol());
if(Sell_takeprofit!=0) TP=OrderOpenPrice()-Sell_takeprofit*AdjustPoint(Symbol());
}
Modified=OrderModify(OrderTicket(),OrderOpenPrice(),SL,TP,0,White);
}
注文時に sl, tp を強制的に設定する方法
変更前
ticket=OrderSend(symbol,OP_BUY,Lots,Ask,Slippage,0,0,NULL,MagicNumber,0,Blue);
if(ticket>=0)
{
if(OrderModify(ticket,OrderOpenPrice(),sl,tp,0))
{
lastTime=now;
entry_cnt++;
}
}
変更後
ticket=OrderSend(symbol,OP_BUY,Lots,Ask,Slippage,sl,tp,NULL,MagicNumber,0,Blue);
if(ticket>=0)
{
lastTime=now;
entry_cnt++;
}
検索結果がありません。 |
検索結果がありません。 |