Not logged in

Forums

Viewing 9 posts - 1 through 9 (of 9 total)

Forums>StrategyQuant (formerly named Genetic Builder)>General Discussion>[BUG] Sometimes ATR based SL/TP wont set by the EA and stays as 0.00000

  • #201142 |
    Karish
    Customer
    571 Posts

    Recently i discovered by my research that there are some EAs with ATR based SL or TP that are working perfectly but sometimes the target that based on an ATR like SL or TP or even both of them will not Modify correctly when the order executed,

    PLUS i havent tested this one but i think it is also effected by this bug: maybe the TrailingStop/BreakEven/etc that are based on ATR are also bugged..

     

    the problem seems to be the calculation of the ATR formula with the target, but i cannot find exact code rows to fix it,

     

    this is a critical bug, some orders are been placed without SL or TP or even both!,

    i will ditch the ATR as my SL/TP for now till we can solve it somehow..,

    would be great if someone from the DEV team will help with that, it is a small problem that should be fixed,

    thank you for your time and attention.

    #201147
    Customer
    356 Posts

    I had a similar problem but won’t go into all the details.  However, I solved my problem via editing the MTFunctions file.

    You’ll notice under exhibit 1 for SL and PT, the return component constraints the value by the checkCorrectMinMaxSLPT.   But under exhibit 2 the TS etc are unconstrained.  The consequence of this for me was the SL and PT were initially placed correctly but under some circumstances (depending on the TS etc formula) subsequent modifications could lead to the SL being modified some 10 greater than the initial SL, the SL being deleted completely etc.

    I solved my issue by modifying the exhibit 2 functions to ensure they are also constrained by the checkCorrectMinMaxSLPT function.

    Hope this helps.

    Exhibit 1:

    double getStopLoss(int tradeDirection) {
    if(tradeDirection == 1) {
    // long
    <#if globalExitRulesContain(“StopLoss”, longExitRules) >
    <#assign exitRule=globalGetExitRule(“StopLoss”, longExitRules) >
    <#if globalIsSLorPTFixedPips(exitRule)>
    return(checkCorrectMinMaxSLPT(<@bbPrintEntryNode exitRule /> * gPointCoef));
    <#else>
    return(checkCorrectMinMaxSLPT(<@bbPrintEntryNode exitRule />));
    </#if>
    </#if>
    } else {
    // short
    <#if globalExitRulesContain(“StopLoss”, shortExitRules) >
    <#assign exitRule=globalGetExitRule(“StopLoss”, shortExitRules) >
    <#if globalIsSLorPTFixedPips(exitRule)>
    return(checkCorrectMinMaxSLPT(<@bbPrintEntryNode exitRule /> * gPointCoef));
    <#else>
    return(checkCorrectMinMaxSLPT(<@bbPrintEntryNode exitRule />));
    </#if>
    </#if>
    }

    return(0);
    }

    ————————————————————————————————–

    double getProfitTarget(int tradeDirection) {
    if(tradeDirection == 1) {
    // long
    <#if globalExitRulesContain(“ProfitTarget”, longExitRules) >
    <#assign exitRule=globalGetExitRule(“ProfitTarget”, longExitRules) >
    <#if globalIsSLorPTFixedPips(exitRule)>
    return(checkCorrectMinMaxSLPT(<@bbPrintEntryNode exitRule /> * gPointCoef));
    <#else>
    return(checkCorrectMinMaxSLPT(<@bbPrintEntryNode exitRule />));
    </#if>
    </#if>
    } else {
    // short
    <#if globalExitRulesContain(“ProfitTarget”, shortExitRules) >
    <#assign exitRule=globalGetExitRule(“ProfitTarget”, shortExitRules) >
    <#if globalIsSLorPTFixedPips(exitRule)>
    return(checkCorrectMinMaxSLPT(<@bbPrintEntryNode exitRule /> * gPointCoef));
    <#else>
    return(checkCorrectMinMaxSLPT(<@bbPrintEntryNode exitRule />));
    </#if>
    </#if>
    }

    return(0);
    }
    //+——————————————————————+

    exhibit 2:

    double getProfitTrailingByTick() {
    if (OrderType() == OP_BUY) {
    // long
    <#if globalExitRulesContain(“TrailingStop”, longExitRules) >
    <#assign exitRule=globalGetExitRule(“TrailingStop”, longExitRules) >
    <#if globalIsSLorPTFixedPips(exitRule)>
    return(<@bbPrintEntryNode exitRule /> * gPointCoef);
    <#else>
    return(<@bbPrintEntryNode exitRule />);
    </#if>
    </#if>
    } else if (OrderType() == OP_SELL) {
    // short
    <#if globalExitRulesContain(“TrailingStop”, shortExitRules) >
    <#assign exitRule=globalGetExitRule(“TrailingStop”, shortExitRules) >
    <#if globalIsSLorPTFixedPips(exitRule)>
    return(<@bbPrintEntryNode exitRule /> * gPointCoef);
    <#else>
    return(<@bbPrintEntryNode exitRule />);
    </#if>
    </#if>
    }

    return(0);
    }

    //+——————————————————————+

    double getStopTrailingByClose() {
    double value = 0;
    if (OrderType() == OP_BUY) {
    <#if globalExitRulesContain(“StopTrailingClose”, longExitRules) >
    <#assign node=globalGetExitRule(“StopTrailingClose”, longExitRules) >
    value = <@bbPrintEntryNode node?children[0] /> + (<@bbPrintEntryNode node?children[1] />) * (<@bbPrintEntryNode node?children[2] />);
    </#if>

    } else if (OrderType() == OP_SELL) {
    <#if globalExitRulesContain(“StopTrailingClose”, shortExitRules) >
    <#assign node=globalGetExitRule(“StopTrailingClose”, shortExitRules) >
    value = <@bbPrintEntryNode node?children[0] /> + (<@bbPrintEntryNode node?children[1] />) * (<@bbPrintEntryNode node?children[2] />);
    </#if>
    }

    return(value);
    }

    //+——————————————————————+

    double getMoveSLValueByTick() {
    if (OrderType() == OP_BUY) {
    // long
    <#if globalExitRulesContain(“StopLossToBreakEven”, longExitRules) >
    <#assign exitRule=globalGetExitRule(“StopLossToBreakEven”, longExitRules) >
    <#if globalIsSLorPTFixedPips(exitRule)>
    return(<@bbPrintEntryNode exitRule /> * gPointCoef);
    <#else>
    return(<@bbPrintEntryNode exitRule />);
    </#if>
    </#if>
    } else if (OrderType() == OP_SELL) {
    // short
    <#if globalExitRulesContain(“StopLossToBreakEven”, shortExitRules) >
    <#assign exitRule=globalGetExitRule(“StopLossToBreakEven”, shortExitRules) >
    <#if globalIsSLorPTFixedPips(exitRule)>
    return(<@bbPrintEntryNode exitRule /> * gPointCoef);
    <#else>
    return(<@bbPrintEntryNode exitRule />);
    </#if>
    </#if>
    }

    return(0);
    }

    • This reply was modified 2 months, 1 week ago by  notch.

    Still trying to import FXBlue statements into QA after 2 years!

    #201150
    Karish
    Customer
    571 Posts

    thank you @notch, but can you be more specific?,

    could you post the exact code that solves this problem for you?,

    and does it solve it completely  or like you said:

    “under some circumstances (depending on the TS etc formula) subsequent modifications could lead to the SL being modified some 10 greater than the initial SL, the SL being deleted completely etc.”

     

    would the problem be solved in 100%?, thank you please post the full code that you modified in order to understand what have been changed, thanks again for your time.

    #201151
    Customer
    356 Posts

    No problem.  I’ll post it later.  I have SQ copied so many times on my hard-drive and I foolishly did not copy the code folder uniformly across copies so I need to dig around.

     

    Actually found it quicker than I thought – ensure all the trailing stop etc have the checkCorrectMinMaxSLPT in the return statement like the following.  This is in the MT4Functions file in the code directory of SQ:

     

    double getProfitTrailingByTick() {
    if (OrderType() == OP_BUY) {
    // long
    <#if globalExitRulesContain(“TrailingStop”, longExitRules) >
    <#assign exitRule=globalGetExitRule(“TrailingStop”, longExitRules) >
    <#if globalIsSLorPTFixedPips(exitRule)>
    return(checkCorrectMinMaxSLPT(<@bbPrintEntryNode exitRule /> * gPointCoef));
    <#else>
    return(checkCorrectMinMaxSLPT(<@bbPrintEntryNode exitRule />));
    </#if>
    </#if>
    } else if (OrderType() == OP_SELL) {
    // short
    <#if globalExitRulesContain(“TrailingStop”, shortExitRules) >
    <#assign exitRule=globalGetExitRule(“TrailingStop”, shortExitRules) >
    <#if globalIsSLorPTFixedPips(exitRule)>
    return(checkCorrectMinMaxSLPT(<@bbPrintEntryNode exitRule /> * gPointCoef));
    <#else>
    return(checkCorrectMinMaxSLPT(<@bbPrintEntryNode exitRule />));
    </#if>
    </#if>
    }

    return(0);
    }

    • This reply was modified 2 months, 1 week ago by  notch.

    Still trying to import FXBlue statements into QA after 2 years!

    #201153
    Customer
    356 Posts

    And it solved it completely.  I wrote under certain circumstances because I sometimes only use a SL and PT so the problem doesn’t arise.  It was a poor use of words.

     

    Still trying to import FXBlue statements into QA after 2 years!

    #201155
    Karish
    Customer
    571 Posts

    @notch Thank you my friend,

    i have modified the code,

    i will try out and see if the problem fixed,

    though the problem was only when the EA was opening and then modifying it to the correct SL/TP because under ECN brokers you have to set SL/TP targets after sending the order it self and not in the same “OrderSend” function,

    so my problem was that when the EA makes that first modification of the order that was just opened then sometimes the SL/TP

    is set to 0.0000 and not the right SL/TP target, it should be something with the calculation of it (“NormalizeDouble” etc…)

     

    however i did modify my code, thank you very much for your time, ill see if it solved the problem

    this is the code that you should replace in MT4Functions.inc

    https://paste.ofcode.org/vhghvwJcihdpn5xupD8Wi5

    #201157
    Customer
    356 Posts

    Hi Karish,

    Thank you for the code.  You are more organised than me!

    The only time I had the ECN place order then modify S/L being 0.0000 is when the price moved to quickly for S/L placement.  Are these scalping EA?  Also did you check the MT4 log files to see whether the EA attempted to set the S/L to a specified value?

     

     

    Still trying to import FXBlue statements into QA after 2 years!

    #201165
    Karish
    Customer
    571 Posts

    not at all, just swings, the log wont show any errors, it seems to be some kind of a calculation problem “NormalizeDouble” or something… never-mind i just turned off ATR as SL/TP and other  Price Rangers from the building blocks, very bugged,

    i’ve been backtesting like 70 different EAs today and trying to match SQ’s equity curve with MT4’s equity curve, turns out that i have turned off ATR as SL/TP and other  Price Rangers from the building blocks as the results does not match with them on by my research, ohhh i cant wait till SQ4 atlest Beta7 😉

    #201167
    Customer
    356 Posts

    No problem.  The log won’t show the error but it will show the attempted modification of the SL and the SL level if any.  It is just noone else seems to have this problem and I’m running 100s of EAs with ATR SLs.  I did have an issue with the price range BB width and price difference but it was due to how I had set the data point and pip size etc.  I just don’t want you to switch off functionality if it isn’t the true cause of the problem.

     

    Anyway, I know you’ll do what’s best.

    Take care.

    Still trying to import FXBlue statements into QA after 2 years!

Viewing 9 posts - 1 through 9 (of 9 total)

You must be logged in to reply to this topic.