adventures of a newbie - page 11

 
niko:
thank CB, i should have noticed that, so the error was right in the end (130).

Is it working then?


CB

 

Hey CB, It is running the trades but I haven't done the detailed going through the trades to see if logic is followed up correctly (it seems to be at first glance). So this is the time I say a massive 'THANK YOU!!!!' :-)

It is still quite a way to go before the strategy is running profitably, as the code is just a way to automate the trades, I need to do a bit of work at my end to refine the strategy itself. Looks like all this effort paid off, but I am still super puzzled with coding. I'm gonna start making little codes on my own to display comments on my charts, and mess about with those, to help me learn functions and other things you used. I super appreciate your help with this CB, and your patience as I kept asking the same thing and making the same mistakes over and over. Thank you!

 
CB, this reminded me of something. How could I make an amednment to your code to allow 2 or max 3 trades to be open in the same direction (this is like a version 2 of your code). We used the OP_BUY/OP_SELL for old code so we will need to change a few things. If you tell me in 'skeleton' form what to do (eg: build a function to do this...) then I can try and code it, and take it back to you for review. This way is better than if you code it yourself, as I get to follow your logic and learn coding bits. What do you reckon? (i can see we'l have an external variable in which we set how many trades we are allowed in same direction, then we do a function to calculate buys, another one to calculate sells, then we call those two functions in start() and check the external variable there as well...something like this?
 

That will be easy.

Set yourself a parameter which is the max number of open orders. Extern it if you require to change frequently.

Then implement by changing only the fnOrderDuplicate() function - you should not have to change the start() function. That will help maintain the existing architecture of the application.


CB

 
man, I wish one day I will be able to say 'that will be easy!'. okay i'l do it, and see what happens! thank you!
 

Hey CB, i spent like 2 hours now trying to do what you asked in the above post, looked at other codes, documentation, and no progress (i just don't know what to do). Man, i keep getting stuck like this, it's so annoying, even with the simplest things! there must be a way to learn easier than how im going at the moment, as i feel i'm not having any progress in learning, you guys are kindly writing all the code for me


bool fnOrderDuplicate()
 {
  iDuplicateOrders = 0;                                  //setting orderdup to zero
  iOrders = OrdersTotal()-1;                             //iOrders returns market orders count - 1. So if zero orders, we get -1
  for (int i=iOrders; i>=0; i--)                         // the loop to cycle through total orders
   {
    OrderSelect(i,SELECT_BY_POS,MODE_TRADES);            //select order for function
    if ((OrderType() != OP_BUY) && (OrderType() != OP_SELL))      //if order is NOT op-buy and is NOT op-sell, sCurrentOrderType = other (ie no order)
     sCurrentOrderType = "OTHER";
    if (OrderType() == OP_BUY)                           //if order=buy, sCurrent OrderType = buy
     sCurrentOrderType = "BUY";                          //***7Jul09 ';' was missing at end of line
    if (OrderType() == OP_SELL)                          //***7Jul09: the end ')' was missing.
     sCurrentOrderType = "SELL";                         //if orderfound = sell, sCurrentOrder= sell
    if ((OrderSymbol() == Symbol()) && (sCurrentOrderType == sSignal))  //if ordersymbolfortheorder= symbolforchart && ScurrentOrder = sSignal(fn_entryrules) 
        iDuplicateOrders++;                              //iDuplicateOrders is added 1
   }
  if (iDuplicateOrders == 0)                             //if iduporders = 0 then fnOrderDuplicate = false, otherwise it's true.
   return(false);
  return(true);
 }
 
hey CB, any help on the above point, how to fix the code to do a multiple trades in 1 direction?
 
niko:
hey CB, any help on the above point, how to fix the code to do a multiple trades in 1 direction?

Just change: if (iDuplicateOrders == 0) to: if (iDuplicateOrders <= iMaxDuplicateOrders)

CB

 

Hey CB, thank you for this. With this option I can not regulate how many open orders are allowed in 1 direction (lets say i make extern iMaxDuplicateOrders = 4;) the ea will run 4 shorts, and not distribute the parameter evenly (eg: 2 shorts max, 2 longs max). Shall I give a go making a duplicate of bool fnOrderDuplicate (eg: bool fnOrderDuplicateBuys, and bool fnOrderDuplicateSells) and then referring to each one respectively in bool fnShouldWeTrade. In my mind this could work, what do you reckon?

 
niko:

Hey CB, thank you for this. With this option I can not regulate how many open orders are allowed in 1 direction (lets say i make extern iMaxDuplicateOrders = 4;) the ea will run 4 shorts, and not distribute the parameter evenly (eg: 2 shorts max, 2 longs max). Shall I give a go making a duplicate of bool fnOrderDuplicate (eg: bool fnOrderDuplicateBuys, and bool fnOrderDuplicateSells) and then referring to each one respectively in bool fnShouldWeTrade. In my mind this could work, what do you reckon?


Setting iMaxDuplicateOrders = 4 will mean that the maximum will be 4 orders in each direction, as we check the direction before incrementing the counter.


Credit where credit's due. The reverse is due in this instance. Apologies - I was already disappointed that you didn't make the amendment yourself. ALL that needed to be done was to change the limit from a single order to a variable.


It is clear from the annotations that you are simply re-creating the code in prose without really understanding the logic.


CB

Reason: