Limiting one entry per pair - page 2

 
RaptorUK:

It would be very odd and I don't think that is what is happening . . . I don't know what is causing your issue to be honest, but clearing up any other little problems might help you with some clarity and help you get to the root cause. I did see a possibility that a Long and a Short could be opened together, but not 2 longs or 2 shorts.

Are you running this in the Strategy Tester or Demo ? or maybe both ?


I am running in Demo. I will clean this up and test again on Sunday/Monday and see if I can get more info on it. Thanks
 

The only mistke I can see is in thinking that the magic number will increase.

Sorry this a repeat but I thought you might have missed it.

 
Ickyrus:
Juat a thought but will not tradecounter always be one and you seem to wish to use it as a magic-number in ordersend to state the order in which the trades were created?

As this is an extern variable, it should not initialize to 0 every time start() is executed so it should always increase by one. Having said this, I am basing this on how the previous platform I used ( Strategy Trader) and assume it will work the same, but it is a good point anyway so I will check. Thanks.
 
arm:

I am running in Demo. I will clean this up and test again on Sunday/Monday and see if I can get more info on it. Thanks
Save yourself some time and test in the Strategy Tester initially . . . it won't show you every lest issue but it will help you find most problems.
 
        totalTrades=OrdersTotal();
        for (int i=0;i<totalTrades-1;i++) {
                if (OrderSelect(i,SELECT_BY_POS)==true) {
                        if (OrderSymbol()==symb)
                                symbCnt++;
                }
                else
                        Print("ERROR: ",GetLastError());
        }

You are counting up but do it also wrong if counting up then

        int i;        
        for (i=0;i<OrdersTotal();i++) {           //not OrdersTotal()-1  with loop counting up

But checking trades make it normal to count down check trades

then it will be like

   int cnt;   
   //... 
   int symbCnt=0;  
   for(cnt = OrdersTotal()-1; cnt >= 0 ; cnt--) //for(cnt=0;cnt<total;cnt++)     
      {      
       OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);     
        if(OrderSymbol()==Symbol())  // check for symbol counting Pending and open trades       
           {         
            //checking the loop
            symbCnt++;         
           }             
      }


   if (symbCnt>0) 
      {
       Print(symbCnt, " ", symb, " Already has open trades. Exiting"); 
       return(0);
      }
 
deVries:

You are counting up but do it also wrong if counting up then

But checking trades make it normal to count down check trades

then it will be like

Thanks deVries and RaptorUK

I am not sure why it is important to count down instead of up, but thanks for catching the following error.

for (int i=0;i<totalTrades-1;i++)

I fixed this and all the other errors caught by RaptorUK and now the transactions are not getting duplicated. This last error could explain why I did not catch the trade as I was missing one iteration, however, it still sounds unlikely that it only happens the first time around. But anyway, the good thing is that it is fixed so I can move on.

Also thanks for suggesting the strategy tester. It speeds development testing quite up a lot.

One last question although not related to this topic: Are the time frames only limited to the time frame enumeration values? or could you use 180 value for a three hour time frame like the following?

iMA(NULL,180,emaFastPeriod,0,MODE_EMA,PRICE_CLOSE,1);
 
arm:

Thanks deVries and RaptorUK

1. I am not sure why it is important to count down instead of up, but thanks for catching the following error.

2. One last question although not related to this topic: Are the time frames only limited to the time frame enumeration values? or could you use 180 value for a three hour time frame like the following?

1. counting down is a must if you are deleting or closing orders: Loops and Closing or Deleting Orders

2. you can use the standard timeframes or other timeframes if you have created them in advance.

 
RaptorUK:

1. counting down is a must if you are deleting or closing orders: Loops and Closing or Deleting Orders

2. you can use the standard timeframes or other timeframes if you have created them in advance.

Thanks that is a very good explanation how the positioning works for OrderSelect().

Sorry for the dumb question but I not sure how to create a time frame in advance. Do you have a link or topic that discusses this?

 
arm:

Sorry for the dumb question but I not sure how to create a time frame in advance. Do you have a link or topic that discusses this?

You need to create it as an offline chart and create the history (hst file), you can use period converter.
 
RaptorUK:
You need to create it as an offline chart and create the history (hst file), you can use period converter.

Ok, figured that out, Thanks. Is possible to do some backtesting with strategy tester with one of these customize cdarts. I made a 3x multiplier on 1H but in strategy tester it does not give me the option to use a 3H timeframe. Is this not possible?
Reason: