检查开放交易的问题 - 页 2

 
dazamate:


int start(){
   static datetime Time0;
   if (Time0 == Time[0]) return; Time0 = Time[0];
   // A new bar has started.

WHRoeder,这段代码看起来很简单,但我不知道它是如何工作的,如果每次当时间0等于时间[0]时,if语句不都是真的吗?不是说它不能工作,但我就是不明白它是如何工作的,它的结构是这样的。

第一次打勾。Time0 不等于Time[0 ],所以不执行返回,Time0 被设置为Time[0](当前条形图的开始时间),其余的启动函数 被执行。

第2个及以后的点:如果Time0 仍然等于当前条形的开始时间,那么我们仍然在同一个条形上,返回被执行,启动函数被退出。如果Time0 不等于当前条形图的开始时间,那么我们就在一个新的条形图上,不执行return, Time0 被设置为Time[0](当前新条形图的开始时间),执行启动函数的其余部分。

 
dazamate:

我如何制作一个计数器,如果一个挂单被放置在那里,并且在X量条内没有被触发,那么它将被取消?我所能想到的是,在每次形成新的条形图时,如果计算的条形图数量==指定的允许条形图,那么挂单就会被取消。每当有新的挂单被打开时,条形计数器就会被重置?这听起来如何?

我将创建一个检查挂单的 函数,它查看每个订单是什么时候开的,检查已经过了多长时间,如果超过了时间限制,就关闭订单。

 
dazamate:

我想做一个函数,在1小时Tf上扫描EURUSD、USDCHF、GBPUSD、USDJPY。它回溯到上一个06:00 gmt蜡烛记录开盘,再回溯到上一个06:00 gmt蜡烛记录开盘,并记录每个货币对的6gmt-6gmt范围。然后比较所有货币对的6gmt-6gmt范围,并返回最高的那个。一个EA有可能通过连接到一个时间图表来做到这一点吗?

像这样的问题,在你考虑代码之前,你必须先弄清楚你的解决方案...IMO。 创建一个流程图或写一些伪代码。...首先得到一个有意义的解决方案...然后再看代码。

回答你的最后一个问题,是的,可以这样做,例如,从不同的货币对中获取特定蜡烛的开盘值,而不是EA所在的货币对,我会使用 ......

iOpen( string symbol, int timeframe, int shift)

一旦你有了4个货币对的愤怒值,你就可以用这样的方法轻松地确定最大的值。

  MathMax( double value4, (MathMax( double value3, (MathMax( double value1, double value2))))) ;

......或者你可以把这些值放入一个数组,然后使用ArraySort ......通常有不止一种方法来做任何事情,首先你必须有一个计划,你将如何解决你的问题。

编辑: 请记住,其中一些东西在策略测试器中 不能正确工作。

 
extern int     iOpenHour                = 6;

int start()
  {
  
int b, scannedhour;
datetime bartime;
double dibsclose, dibsopen, prevdayrange;

for(b=0; b<=24; b++)                                   // scans the last 24 bars 
   {
      bartime = iTime("EURUSD", 60, b);                // checks the open time of each bar
      scannedhour = TimeHour(bartime);                 // extracts the hour of that bar
    
      if ( scannedhour == iOpenHour )                  // Check to see if scanned hour = Dibs hour
         {
            dibsclose    = iOpen("EURUSD", 60, b);     // Get the open value of that bar (Close of 6gmt day) 
            dibsopen     = iOpen("EURUSD", 60, b-24);  // Get the value of the bar 24 bars before the Dibs bar (Open of 6gmt day)
            prevdayrange = (dibsclose-dibsopen);       // Calculate the range of the Dibs day
         }                                             // End of if statement
    }                                                  // End of for statement


Comment("Prev Dibs day range is...",prevdayrange, "dibsclose  =  ", dibsclose, "dibsopen  =  ",dibsopen, "Scannedhour=",scannedhour);      


   return(0);
  }

好吧,这是我自己尝试写的一些代码,它可以扫描金牛座1小时图,直到找到最后一个06:00的酒吧,记录它的开盘,回到另外24个酒吧,记录该酒吧的开盘(06:00日的开始),并从这两个选定的酒吧获得开盘-开盘范围。

令人惊讶的是,这并不奏效。Lol ------> http://myfacewhen.com/307/

告诉我,我犯了什么错?或者我只是用错了方法?我试过了,嘿嘿

 

发现了一个问题......。 24小时前的b是b+24 ......条形图从当前条形图(0)向左数起。

dibsopen     = iOpen("EURUSD", 60, b-24);  // Get the value of the bar 24 bars before the Dibs bar (Open of 6gmt day)

change to:

dibsopen     = iOpen("EURUSD", 60, b+24);  // Get the value of the bar 24 bars before the Dibs bar (Open of 6gmt day)

做得好,添加了评论,这是非常好的做法 ... ...)

 
RaptorUK:

发现了一个问题......。 24小时前的b是b+24 ......条形图从当前条形图(0)向左数起。

做得好,添加了评论,这是非常好的做法 ... ...)


哇,很好地发现了这一点,我花了好长时间才弄明白,笑。我真不敢相信我把所有的事情都做对了--那个愚蠢的错误。我觉得我现在有了点进展。是的,我添加了评论,以帮助我跟踪我正在做的事情,并使你们超级容易看到我正在尝试做的事情。现在,我打算让它比较4个对子,并吐出价值最高的一个,我会让你知道我是怎么做的。谢谢 RaptorUK
 
好东西,做得很好。 不客气 :-)
 
extern int     iOpenHour                = 6;

int start()
  {
                                                            //  Array Categorys ( 1  EURUSD, 2 GBPUSD, 3 USDCHF, 4 USDJPY )
int b[4], scannedhour[4];
datetime bartime[4];
double dibsclose[4], dibsopen[4], prevdayrange[4];

//----------------------------------------------------------------------------------------------
//        EURUSD PREV DAY RANGE CALC

for(b[1]=0; b[1]<=24; b[1]++)                               // scans the last 24 bars on eurusd
   {
      bartime[1] = iTime("EURUSD", 60, b[1]);               // checks the open time of each bar
      scannedhour[1] = TimeHour(bartime[1]);                // extracts the hour of that bar
    
      if ( scannedhour[1] == iOpenHour )                    // Check to see if scanned hour = Dibs hour
         {
            dibsclose[1]    = iOpen("EURUSD", 60, b[1]);    // Get the open value of that bar (Close of 6gmt day) 
            dibsopen[1]     = iOpen("EURUSD", 60, b[1]+24); // Get the value of the bar 24 bars before the Dibs bar (Open of 6gmt day)
            prevdayrange[1] = (dibsclose[1]-dibsopen[1]);   // Calculate the range of the Dibs day
         }                                                  // End of if statement
    }                                                       // End of for statement
    

//----------------------------------------------------------------------------------------------
//        GBPUSD PREV DAY RANGE CALC

for(b[2]=0; b[2]<=24; b[2]++)                               // scans the last 24 bars on eurusd
   {
      bartime[2] = iTime("GBPUSD", 60, b[2]);               // checks the open time of each bar
      scannedhour[2] = TimeHour(bartime[2]);                // extracts the hour of that bar
    
      if ( scannedhour[2] == iOpenHour )                    // Check to see if scanned hour = Dibs hour
         {
            dibsclose[2]    = iOpen("GBPUSD", 60, b[2]);    // Get the open value of that bar (Close of 6gmt day) 
            dibsopen[2]     = iOpen("GBPUSD", 60, b[2]+24); // Get the value of the bar 24 bars before the Dibs bar (Open of 6gmt day)
            prevdayrange[2] = (dibsclose[2]-dibsopen[2]);   // Calculate the range of the Dibs day
         }                                                  // End of if statement
    }                                                       // End of for statement



//----------------------------------------------------------------------------------------------
//        USDCHF PREV DAY RANGE CALC

for(b[3]=0; b[3]<=24; b[3]++)                               // scans the last 24 bars on eurusd
   {
      bartime[3] = iTime("EURUSD", 60, b[3]);               // checks the open time of each bar
      scannedhour[3] = TimeHour(bartime[3]);                // extracts the hour of that bar
    
      if ( scannedhour[3] == iOpenHour )                    // Check to see if scanned hour = Dibs hour
         {
            dibsclose[3]    = iOpen("USDCHF", 60, b[3]);    // Get the open value of that bar (Close of 6gmt day) 
            dibsopen[3]     = iOpen("USDCHF", 60, b[3]+24); // Get the value of the bar 24 bars before the Dibs bar (Open of 6gmt day)
            prevdayrange[3] = (dibsclose[3]-dibsopen[3]);   // Calculate the range of the Dibs day
         }                                                  // End of if statement
    }                                                       // End of for statement


//----------------------------------------------------------------------------------------------
//        USDJPY PREV DAY RANGE CALC

for(b[4]=0; b[4]<=24; b[4]++)                               // scans the last 24 bars on eurusd
   {
      bartime[4] = iTime("USDJPY", 60, b[4]);               // checks the open time of each bar
      scannedhour[4] = TimeHour(bartime[4]);                // extracts the hour of that bar
    
      if ( scannedhour[4] == iOpenHour )                    // Check to see if scanned hour = Dibs hour
         {
            dibsclose[4]    = iOpen("USDJPY", 60, b[4]);    // Get the open value of that bar (Close of 6gmt day) 
            dibsopen[4]     = iOpen("USDJPY", 60, b[4]+24); // Get the value of the bar 24 bars before the Dibs bar (Open of 6gmt day)
            prevdayrange[4] = (dibsclose[4]-dibsopen[4]);   // Calculate the range of the Dibs day
         }                                                  // End of if statement
    }                                                       // End of for statement




//----------------------------------------------------------------------------------------------



Comment("DIBS RANGE EURUSD:...", prevdayrange[1],        //Display Ranges of each pair
        "DIBS RANGE GBPUSD:...", prevdayrange[2],
        "DIBS RANGE USDCHF:...", prevdayrange[3],
        "DIBS RANGE USDJPY:...", prevdayrange[4]);      


   return(0);
  }
好吧,我把所有的变量变成了数组,并对每个变量进行了检查。现在它已经停止工作了。像这样有多个for循环是不可能的吗?
 
dazamate:
好吧,我把所有的变量变成了数组,并对每个变量进行了检查。现在它已经停止工作了。像这样有多个for循环是不可能的吗?
是的,你可以,没问题,但不要在for循环的索引中使用数组,如果你愿意,你可以每次都使用b。它在每个for循环中都被重置为0,所以重新使用它不是问题。你实际上需要使用数组做什么?
 
RaptorUK:
是的,你可以,没有问题,但不要在for循环的索引中使用数组,如果你愿意,你可以每次都使用b。它在每个for循环中都被重置为0,所以重新使用它不是问题。你实际上需要使用数组做什么?
啊,是的,我明白你的意思了,我把它修好,看看我怎么做。如果这个EA能让我发财,我会付给你一些美元。