지옥에 젠장 오류 130 - 페이지 4

 

k... 내일 코드를 게시할 예정입니다...

이것이 백테스터 에서 일어나는 일이라는 것을 언급하는 것을 잊었습니다... 앞으로 어떻게 될지 모르지만 확실히 저는 여기서 이것을 보고 싶지 않습니다.

 
int PriceOpenMode(int op)
  {
  if (op==OP_BUY)
     return(MODE_ASK);
  if (op==OP_SELL)
     return(MODE_BID);
  return(-1);
  }


int PriceCloseMode(int op)
  {
  if (op==OP_BUY)
     return(MODE_BID);
  if (op==OP_SELL)
     return(MODE_ASK);
  return(-1);
  }
  


int ReliableOrderSend(string symbol,int cmd,double volume,double price,int slippage,double stoploss,double takeprofit, string comment="",int magic=0,datetime expiration=0,color arrow_color=CLR_NONE,int MaxPasses=0) 
  {  
  int Gle=ERR_TRADE_CONTEXT_BUSY;        
  int passes=0;  
  int res=-1;  
  while (Gle==ERR_TRADE_CONTEXT_BUSY||Gle==ERR_REQUOTE||Gle==ERR_INVALID_PRICE||Gle==ERR_PRICE_CHANGED||Gle==ERR_OFF_QUOTES)
       {  
          
       if (Gle==ERR_REQUOTE||Gle==ERR_INVALID_PRICE||Gle==ERR_PRICE_CHANGED||Gle==ERR_OFF_QUOTES||passes==0)
         {
         if (passes!=0)
            RefreshRates();
         if (price==0.0)  //if (passes!=0||price==0)
            price=MarketInfo(symbol,PriceOpenMode(cmd));
         }//if (Gle==ERR_REQUOTE)                        
       res=OrderSend(symbol,cmd,volume,price,slippage,stoploss,takeprofit,comment,magic,expiration,arrow_color);   
       Gle=GetLastError();       
       if (Gle!=ERR_NO_ERROR)
          Print("ReliableOrderSend error : ",Gle);              
       passes=passes+1;
       
       if (MaxPasses!=0)
         {
          if (passes>=MaxPasses)
            break;
         }

       if (Gle==ERR_REQUOTE||Gle==ERR_INVALID_PRICE||Gle==ERR_PRICE_CHANGED||Gle==ERR_OFF_QUOTES) { price=0.0; }
         
       }//while (Gle==ERR_TRADE_CONTEXT_BUSY||Gle==ERR_REQUOTE)       
  return(res);
  }
     

bool ReliableOrderClose(int ticket, double lots, double price, int slippage, color Color=CLR_NONE,int MaxPasses=0) 
  {
  int Gle=ERR_TRADE_CONTEXT_BUSY;
  int passes=0;  
  bool res;
  int otype;
  double olots;
  string osymbol;
  res=OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES);
  osymbol=OrderSymbol();
  otype=OrderType();
  olots=OrderLots();  
  if (lots==0)
     lots=olots;  
  if (res==True)
    {
    while (Gle==ERR_TRADE_CONTEXT_BUSY||Gle==ERR_REQUOTE||Gle==ERR_INVALID_PRICE||Gle==ERR_PRICE_CHANGED||Gle==ERR_OFF_QUOTES)
       {     
       if (Gle==ERR_REQUOTE||Gle==ERR_INVALID_PRICE||Gle==ERR_PRICE_CHANGED||Gle==ERR_OFF_QUOTES||passes==0)
         {
         if (passes!=0)
            RefreshRates();
         if (price==0.0)  //if (passes!=0||price==0)
            price=MarketInfo(osymbol,PriceCloseMode(otype));
         }//if (Gle==ERR_REQUOTE)                               
       res=OrderClose(ticket,lots,price,slippage,Color);   
       Gle=GetLastError();
       if (Gle!=ERR_NO_ERROR)
          Print("ReliableOrderClose error : ",Gle);           
       passes=passes+1;
       
       if (MaxPasses!=0)
         {
          if (passes>=MaxPasses)
            break;
         }
       
       if (Gle==ERR_REQUOTE||Gle==ERR_INVALID_PRICE||Gle==ERR_PRICE_CHANGED||Gle==ERR_OFF_QUOTES) { price=0.0; }

       }//while (Gle==ERR_TRADE_CONTEXT_BUSY||Gle==ERR_REQUOTE)  
    }
  return(res);
  }
 
bool ReliableModifyStopLoss(int ticket,double NewStopLoss,int MarkColor=CLR_NONE)
  {
  int ot,oti;
  datetime oex;
  string os;
  double oop,otp,point;
  bool res=false;
  bool selected=false;  
  double fixed;
  selected=OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES);   
  if (selected==True)
    {
     double ns=NormalizeDouble(NewStopLoss,MarketInfo(OrderSymbol(),MODE_DIGITS));
     ot=OrderType();     
     oti=OrderTicket();
     oop=OrderOpenPrice();
     otp=OrderTakeProfit();
     oex=OrderExpiration();
     os=OrderSymbol();
     point=MarketInfo(os,MODE_POINT);
     if (ot==OP_BUY||ot==OP_BUYSTOP||ot==OP_BUYLIMIT)
       {       
        fixed=MarketInfo(os,MODE_ASK)-MarketInfo(os,MODE_STOPLEVEL)*point;
        if (ns>fixed&&ns<=MarketInfo(os,MODE_ASK))
          ns=fixed;
        while(true)
          {
           res=OrderModify(oti,oop,ns,otp,oex,MarkColor);
           if (res==True)
             break;
           else 
            {
             if (GetLastError()==ERR_INVALID_STOPS)               
               ns=ns-point;
             else
               break;
            }
           RefreshRates();
          }//while(true)
       }//if (ot==OP_BUY||ot==OP_BUYSTOP||ot==OP_BUYLIMIT)
     if (ot==OP_SELL||ot==OP_SELLSTOP||ot==OP_SELLLIMIT)
       {
        fixed=MarketInfo(os,MODE_BID)+MarketInfo(os,MODE_STOPLEVEL)*point;
        if (ns<fixed&&ns>=MarketInfo(os,MODE_BID))
          ns=fixed;       
        while(true)
          {           
           res=OrderModify(oti,oop,ns,otp,oex,MarkColor);
           if (res==True)
             break;
           else 
            {
             if (GetLastError()==ERR_INVALID_STOPS)               
               ns=ns+point;             
             else
               break;
            }
           RefreshRates();
          }//while(true)
       }//if (ot==OP_BUY||ot==OP_BUYSTOP||ot==OP_BUYLIMIT)
    }   
  return(res);  
  }

bool ReliableModifyTakeProfit(int ticket,double NewTakeProfit,int MarkColor=CLR_NONE)
  {
  int ot,oti;
  datetime oex;
  string os;
  double oop,osl,point;
  bool res=false;
  bool selected=false;  
  double fixed;
  selected=OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES);   
  if (selected==True)
    {
     double nt=NormalizeDouble(NewTakeProfit,MarketInfo(OrderSymbol(),MODE_DIGITS));
     ot=OrderType();     
     oti=OrderTicket();
     oop=OrderOpenPrice();
     osl=OrderStopLoss();
     oex=OrderExpiration();
     os=OrderSymbol();
     point=MarketInfo(os,MODE_POINT);
     if (ot==OP_BUY||ot==OP_BUYSTOP||ot==OP_BUYLIMIT)
       {       
        fixed=MarketInfo(os,MODE_ASK)+MarketInfo(os,MODE_STOPLEVEL)*point;       
        if (nt<fixed&&nt>=MarketInfo(os,MODE_ASK))
          nt=fixed;
        while(true)
          {           
           res=OrderModify(oti,oop,osl,nt,oex,MarkColor);
           if (res==True)
             break;
           else 
            {
             if (GetLastError()==ERR_INVALID_STOPS)               
               nt=nt+point;
             else
               break;
            }
           RefreshRates();
          }//while(true)
       }//if (ot==OP_BUY||ot==OP_BUYSTOP||ot==OP_BUYLIMIT)
     if (ot==OP_SELL||ot==OP_SELLSTOP||ot==OP_SELLLIMIT)
       {
        fixed=MarketInfo(os,MODE_BID)-MarketInfo(os,MODE_STOPLEVEL)*point;
        if (nt>fixed&&nt<=MarketInfo(os,MODE_BID))
          nt=fixed;       
        while(true)
          {           
           res=OrderModify(oti,oop,osl,nt,oex,MarkColor);
           if (res==True)
             break;
           else 
            {
             if (GetLastError()==ERR_INVALID_STOPS)               
               nt=nt-point;             
             else
               break;
            }
           RefreshRates();
          }//while(true)
       }//if (ot==OP_BUY||ot==OP_BUYSTOP||ot==OP_BUYLIMIT)
    }   
  return(res);  
  }


int ReliableOrderPlace(string symbol,int cmd,double volume,double price,int slippage,int stoploss,int takeprofit, string comment="",int magic=0,datetime expiration=0,color arrow_color=CLR_NONE,int MaxPasses=0) 
  {
   int res,ticket;
   double oop,tkp,osl;
   res=ReliableOrderSend(symbol,cmd,volume,price,slippage,0,0,comment,magic,expiration,arrow_color,MaxPasses); 
   if (res!=-1)
     {
      ticket=OrderSelect(res,SELECT_BY_TICKET,MODE_TRADES);      
      oop=OrderOpenPrice();
      if (takeprofit!=0)
        {
         if (cmd==OP_BUY||cmd==OP_BUYLIMIT||cmd==OP_BUYSTOP)
           tkp=oop+takeprofit*MarketInfo(symbol,MODE_POINT);
         if (cmd==OP_SELL||cmd==OP_SELLLIMIT||cmd==OP_SELLSTOP)
           tkp=oop-takeprofit*MarketInfo(symbol,MODE_POINT);         
         ReliableModifyTakeProfit(res,tkp);
        }
     }
   if (res!=-1)
     {
      ticket=OrderSelect(res,SELECT_BY_TICKET,MODE_TRADES);      
      oop=OrderOpenPrice();
      if (stoploss!=0)
        {
         if (cmd==OP_BUY||cmd==OP_BUYLIMIT||cmd==OP_BUYSTOP)
           osl=oop-stoploss*MarketInfo(symbol,MODE_POINT);
         if (cmd==OP_SELL||cmd==OP_SELLLIMIT||cmd==OP_SELLSTOP)
           osl=oop+stoploss*MarketInfo(symbol,MODE_POINT);         
         ReliableModifyStopLoss(res,osl);
        }
     }
    return(res);
  }
 
잘? 어떤 아이디어?
 
Roger wrote >>

이제 전체 코드를 보여줄 때입니다. 망설이시면 PM을 이용하시면 됩니다.

입찰가보다 TP가 낮습니다.

TP < Bid Issue를 수정한 후 이 브로커에 대한 내 정지 수준이 0인 것으로 밝혀져 주문에 SL 또는 TP를 가질 수 없었고 주문한 직후에 주문 수정을 사용해야 했습니다.

당신의 도움을 주셔서 감사합니다,

비비

 

실제 생산 라인을 게시하지 않았기 때문에 TP 세트를 어디에서 볼 수 있는지 알 수 없습니다.

tsel = ReliableOrderSend ( Symbol ( ) , WhatOperation ( OP_SELL , GetPylonRoot ( execpyl , MODE_HIGH ) + ( 2 * Half ) * ( BuildLevels + execlev ) ) , LotSize , HighBase + ( 2 * Half ) * ( BuildLevels + execlev ) , Slippage , 0 , 0 , "" , MakeMagic ( execpyl , execlev + 1 , execarea ) ) ;
보시다시피 SL과 TP는 모두 0으로 설정되어 있습니다.
 

WOAA....내 잘못입니다. 가격이 같은 공식이 아닙니다.

나중에 편집:

수정해도 문제가 해결되지 않습니다... 동일한 발생은 아니지만 여전히 발생합니다.

 
해결 ... SL 또는 TP가 없을 때 STOPLEVEL은 여전히 중요합니다 ...