Order Opening Logic and Best Practice
Results 1 to 8 of 8

Thread: Order Opening Logic and Best Practice

  1. #1
    I would like assistance with placing the logic correctly for order opening.... What is the best practice to open an order if the price hits a line? (additionally, with Slippage)
    =============================

    Factors for Order Opening:
    Inserted Code int I; // Bar index int Counted_bars; // Number of counted bars Counted_bars=IndiorCounted(); // Number of counted pubs I=Bars-Counted_bars-1; // Index of the initial uncounted while(igt;=0) // Loop for uncounted pubs double MA_Line=iCustom(NULL,timeframe,MA StdDev,MA_Period, 1, 6, 0, 0,I); double S_Line1=iCustom(NULL,timeframe,MA StdDev,MA_Period, 1, 6, 2, 0, 1,I); double S_Line2=iCustom(NULL,timeframe,MA StdDev,MA_Period, 1, 6, 2, 0, 2,I); double S_Line3=iCustom(NULL,timeframe,MA StdDev,MA_Period, 1, 6, 2, 0, 3,I); double S_Line4=iCustom(NULL,timeframe,MA StdDev,MA_Period, 1, 6, 2, 0, 4,I); double U_StopLoss=iCustom(NULL,timeframe,MA StdDev,MA_Period, 1, 6, 2, 0, 5,I); double L_StopLoss=iCustom(NULL,timeframe,MA-StdDev,MA_Period, 1, 6, 2, 0, 5,I); double B_Line1=iCustom(NULL,timeframe,MA-StdDev,MA_Period, 1, 6, 0, 1,I); double B_Line2=iCustom(NULL,timeframe,MA-StdDev,MA_Period, 1, 6, 0, 2,I); double B_Line3=iCustom(NULL,timeframe,MA-StdDev,MA_Period, 1, 6, 2, 0, 3,I); double B_Line4=iCustom(NULL,timeframe,MA-StdDev,MA_Period, 1, 6, 2, 0, 4,I); double StochBuyLine = iStochastic(Symbol(),0,14,3,3,1,1,0,I); double StochSellLine = iStochastic(Symbol(),0,14,3,3,1,1,1,I); I--;
    Logic needing inspection and advice:

    Inserted Code if (Tradeable) else break; should CurrentPrice lt; MA_Line if StochBuyLinegt;StochSellLine StochBuyLinelt;=10 CurrentPrice = B_Line4 OpenBuyOrder @ Line4LotSize Else if StochBuyLinegt;StochSellLine StochBuyLinelt;=10 CurrentPrice = B_Line3 OpenBuyOrder @ Line3LotSize Else if StochBuyLinegt;StochSellLine StochBuyLinelt;=10 CurrentPrice = B_Line2 OpenBuyOrder @ Line2LotSize Else if StochBuyLinegt;StochSellLine StochBuyLinelt;=10 CurrentPrice = B_Line1 OpenBuyOrder @ Line1LotSize Else if StochSellLinegt;StochBuyLine StochSellLinegt;=90 CurrentPrice = B_Line4 OpenBuyOrder @ Line4LotSize Else if StochSellLine StochSellLinegt;=90 CurrentPrice = B_Line3 OpenBuyOrder @ Line3LotSize Else if StochSellLinegt;StochBuyLine StochSellLinegt;=90 CurrentPrice = B_Line2 OpenBuyOrder @ Line2LotSize Else if StochSellLinegt;StochBuyLine StochSellLinegt;=90 CurrentPrice = B_Line1 OpenBuyOrder @ Line1LotSize #91;ribbon=quot#93;#91;/font#93;

  2. #2
    Several Items:

    1. If that block of code is out of your EA. Get rid of the while loop. It isn't needed. Either assign I0 to the current bar or=1 to the former pub. Because your EA does not care what happened 3000 bars 19, no need to loop back in time.

    2. Where you've currentprice = B_Line4 (and the rest) a single = sign is an assignment operator. To check for equality two == signals will be needed by you.

    3. On that exact same subject it is improbable that price will be exactly the same as the value to your lines. If the line reaches 123.4554332 and the price is at 123.45, mt4 will consider these not to be equivalent. Either use NormalizeDouble or check to see if price has crossed the line.

    4. Check with an ordersend function. ordersend will return an integer.

    5. Slippage is left up to you. But I can assure that what works in presentation will not necessarily work in reside. That is why you check with an ordersend function. Sometimes you want to slap the server 2-3 times before it takes the order.

  3. #3
    Either utilize NormalizeDouble or check to determine if price has crossed the line.

    Can you show me an instance of a cross line check? ... though I'd prefer logic to try and get it hits the line... so I guess NormalizeDouble ought to be the way I move then

  4. #4
    If you're looking for it to cross going up....

    If(Open[0] lt; the lineup Close[0] gt;= the line) it crossed up


    going down

    if(Open[0] gt; the lineup Close[0] lt;= the line) it crossed down

  5. #5
    Gotcha... what normally is best practice? Hitting on the lineup or crossing over?

  6. #6
    Quote Originally Posted by ;
    Gotcha... what generally is best practice? Hitting on the lineup or crossing over?
    I would do cross over. Sometimes price will jump two pips or more and simply leap over being equivalent. You can check for cross over and then make price is within 1-2 pips of this line.

  7. #7
    So, can I do anything similar to this?

    Inserted Code if line4tradeslt;1 StochBuyLinegt;StochSellLine StochBuyLinelt;=10 CurrentPrice= = B_Line4 ( (Open#91;0#93; lt; the line Near#91;0#93; gt;= the line)||(Open#91;0#93; gt; the line Near#91;0#93; lt;= the line line))

  8. #8
    Seems like my response to the slipped through the cracks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
This website uses cookies
We use cookies to store session information to facilitate remembering your login information, to allow you to save website preferences, to personalise content and ads, to provide social media features and to analyse our traffic. We also share information about your use of our site with our social media, advertising and analytics partners more information