Fibo bug! finally found the bug and fix explained

OK so first of all there is a problem where this does not act symmetrically and I have identified the two bugs below and explained how to fix them!

//--------------------------------------------------------------------
// Trading rule: Long entry (On Bar Open)
//--------------------------------------------------------------------                   
if ((LongEntrySignal
   and Not LongExitSignal)
   and (MarketPosition("Current", MagicNumber, "") is Not Long))
{
    // Action #1
    Open Long order at (Fibo(Main chart, High-low previous week, Fibo Level = -23.6)[] + (ATR(Main chart,ATRPeriod1)[2] * PriceEntryMult1)) Limit;
        Order valid for BarsValid bars;
        Duplicate trades: allowed;
        Replacing pending orders: allowed; 
         
        Stop Loss = SLm * ATR(SLp);
}


//--------------------------------------------------------------------
// Trading rule: Short entry (On Bar Open)
//--------------------------------------------------------------------                   
if ((ShortEntrySignal
   and Not ShortExitSignal)
   and (MarketPosition("Current", MagicNumber, "") is Not Short))
{
    // Action #1
    Open Short order at (Fibo(Main chart, High-low previous week, Fibo Level = 123.6)[] - (ATR(Main chart,ATRPeriod1)[2] * PriceEntryMult1)) Limit;
        Order valid for BarsValid bars;
        Duplicate trades: allowed;
        Replacing pending orders: allowed; 
         
        Stop Loss = SLm * ATR(SLp);
}


Bug#1
there is no 123.6 is available in the dropdown of algowizard for fibo levels.

Bug#2
 Java is already reversing the calculation Low-High instead of High-Low depending on if it's a bullish or bearish reading so there is no need to also reverse the fibo level number! Just leave the level the same and all will be symmetrical! For cosmetics you could show Low-High in the pseudocode and to fix the symmetry issue, you would keep the levels the same so the above becomes:

//--------------------------------------------------------------------
// Trading rule: Long entry (On Bar Open)
//--------------------------------------------------------------------                   
if ((LongEntrySignal
   and Not LongExitSignal)
   and (MarketPosition("Current", MagicNumber, "") is Not Long))
{
    // Action #1
    Open Long order at (Fibo(Main chart, High-low previous week, Fibo Level = -23.6)[] + (ATR(Main chart,ATRPeriod1)[2] * PriceEntryMult1)) Limit;
        Order valid for BarsValid bars;
        Duplicate trades: allowed;
        Replacing pending orders: allowed; 
         
        Stop Loss = SLm * ATR(SLp);
}



//--------------------------------------------------------------------
// Trading rule: Short entry (On Bar Open)
//--------------------------------------------------------------------                   
if ((ShortEntrySignal
   and Not ShortExitSignal)
   and (MarketPosition("Current", MagicNumber, "") is Not Short))
{
    // Action #1
    Open Short order at (Fibo(Main chart, low-High previous week, Fibo Level = -23.6)[] - (ATR(Main chart,ATRPeriod1)[2] * PriceEntryMult1)) Limit;
        Order valid for BarsValid bars;
        Duplicate trades: allowed;
        Replacing pending orders: allowed; 
         
        Stop Loss = SLm * ATR(SLp);
}



The orange is cosmetic only for pseudocode, the java is already acting that way. This will fix the symmetry issue 100%.


As for the signal, since long signal and short signal are not necessarily mutually exclusive to the bullish and bearish reading of the fibo, I strongly recommend making them so because a bearish fibo reading makes no sense for a bullish signal.

//--------------------------------------------------------------------
// Trading rule: Long entry (On Bar Open)
//--------------------------------------------------------------------                   
if ((LongEntrySignal
   and Not LongExitSignal)
   and (MarketPosition("Current", MagicNumber, "") is Not Long))
{

    // Action #1
    *****if (previous week is bullish)***** Open Long order at (Fibo(Main chart, High-low previous week, Fibo Level = -23.6)[] + (ATR(Main chart,ATRPeriod1)[2] * PriceEntryMult1)) Limit;
        Order valid for BarsValid bars;
        Duplicate trades: allowed;
        Replacing pending orders: allowed; 
         
        Stop Loss = SLm * ATR(SLp);
}



//--------------------------------------------------------------------
// Trading rule: Short entry (On Bar Open)
//--------------------------------------------------------------------                   
if ((ShortEntrySignal
   and Not ShortExitSignal)
   and (MarketPosition("Current", MagicNumber, "") is Not Short))
{
    // Action #1
    *****if (previous week is bearish)***** Open Short order at (Fibo(Main chart, low-High previous week, Fibo Level = -23.6)[] - (ATR(Main chart,ATRPeriod1)[2] * PriceEntryMult1)) Limit;
        Order valid for BarsValid bars;
        Duplicate trades: allowed;
        Replacing pending orders: allowed; 
         
        Stop Loss = SLm * ATR(SLp);
}




Attachments
  • Votes +3
  • Project StrategyQuant X
  • Type Bug
  • Status Fixed
  • Priority Normal

History

b
#1

bentra

20.07.2022 16:25

Task created

b
#2

bentra

20.07.2022 16:28
Voted for this task.
b
#3

bentra

20.07.2022 16:28

Attachment Strategy 169181-fixed.sqx added

Attachment Strategy 169181-bugged.sqx added

Strategy 169181-bugged.sqx
(710.20 KiB)
Strategy 169181-fixed.sqx
(883.35 KiB)
E
#4

Emmanuel

06.08.2022 15:35
Voted for this task.
b
#5

bentra

18.09.2022 18:26
In short we have 2 different things flipping the levels around, this bit of code in the java:


fiboLevel = bullish ? (upperValue - delta) : (lowerValue + delta);


and


the opposite logic changing the levels such as -23.6 --> 123.6 via the formula: Reverse_Fibo_Level = 100 - Original_Fibo_Level 

We need to have only ONE of these two things. 

CG
#6

Chris G

22.09.2022 14:23
Voted for this task.
b
#7

bentra

03.10.2022 17:04
This is a relatively easy fix....
b
#8

bentra

04.12.2022 23:05
Hey this is an easy fix and we missed the milestone...
b
#9

bentra

06.12.2022 06:03
It would be nice if this could be symmetrical at least for b136 please:

In short we have 2 different things flipping the levels around, this bit of code in the java:


fiboLevel = bullish ? (upperValue - delta) : (lowerValue + delta);


and


the opposite logic changing the levels such as -23.6 --> 123.6 via the formula: Reverse_Fibo_Level = 100 - Original_Fibo_Level 

We need to have only ONE of these two things. 

MF
#10

Mark Fric

06.12.2022 09:11

Status changed from New to Fixed

but this is already fixed, have you tried it with 136 RC3?


The negation is like this, which I believe is correct:

LongEntrySignal = ((Fibo(Main chart, Open-Close previous week, Fibo Level = 23.6)[] < Fibo(Main chart, High-low previous week, Fibo Level = -23.6)[])
   and (Fibo(Main chart, High-Low previous day, Fibo Level = 23.6)[] = Fibo(Main chart, High-Low previous day, Fibo Level = -61.8)[]));

ShortEntrySignal = ((Fibo(Main chart, Open-Close previous week, Fibo Level = 76.4)[] > Fibo(Main chart, High-low previous week, Fibo Level = 123.6)[])
   and (Fibo(Main chart, High-Low previous day, Fibo Level = 76.4)[] <> Fibo(Main chart, High-Low previous day, Fibo Level = 161.8)[]));
b
#11

bentra

06.12.2022 09:53
in RC3 the following bit of code still exists in the java:

fiboLevel = bullish ? (upperValue - delta) : (lowerValue + delta);


This will cause the levels to flip around depending on fibolevel = bullish or not.... So if we get a "fibolevel != bullish" we are now facing the wrong way for shorts when bearish. We want to be facing the right way for shorts. so you can leave the java and change the negate to be like this:

LongEntrySignal = ((Fibo(Main chart, Open-Close previous week, Fibo Level = 23.6)[] < Fibo(Main chart, High-low previous week, Fibo Level = -23.6)[])
   and (Fibo(Main chart, High-Low previous day, Fibo Level = 23.6)[] = Fibo(Main chart, High-Low previous day, Fibo Level = -61.8)[]));


ShortEntrySignal = ((Fibo(Main chart, Open-Close previous week, Fibo Level = 23.6)[] > Fibo(Main chart, High-low previous week, Fibo Level = -23.6)[])
   and (Fibo(Main chart, High-Low previous day, Fibo Level = 23.6)[] <> Fibo(Main chart, High-Low previous day, Fibo Level = -61.8)[]));


Because the java is already reversing the levels

b
#12

bentra

06.12.2022 10:15
btw that was a terrible example. But you can see what I mean in the original description.

Hopefully you can see the problem, the levels are being flipped around 2x. once by the negater and once by the java. If we want symmetry we need to flip them around only once.
b
#13

bentra

06.12.2022 10:53

Yes I just tested RC3.... I can turn 47.14% trade symmetry in to 94.35% trade symmetry by manually changing the fibolevels to be the same:

THIS ONE CAME FROM BUILDER RC3 AND HAS 47.14% TRADE SYMMETRY

//--------------------------------------------------------------------
// Trading rule: Long entry (On Bar Open)
//--------------------------------------------------------------------                   
if ((LongEntrySignal
   and Not LongExitSignal)
   and (MarketPosition("Current", MagicNumber, "") is Not Long))
{
    // Action #1
    Open Long order at (Fibo(Main chart, Open-Close previous week, Fibo Level = -38.2)[] + (ATR(Main chart,ATRPeriod1)[5] * PriceEntryMult1)) Stop;
        Order valid for BarsValid bars;
        Duplicate trades: allowed; 
        Replacing pending orders: allowed; 
        Stop Loss = SLm * ATR(mATRp);
        Profit target = TPm * ATR(mATRp);

        Trailing Stop = TSm * ATR(mATRp);

        Exit After ExitAfterBars bars;
}


//--------------------------------------------------------------------
// Trading rule: Short entry (On Bar Open)
//--------------------------------------------------------------------                   
if ((ShortEntrySignal
   and Not ShortExitSignal)
   and (MarketPosition("Current", MagicNumber, "") is Not Short))
{
    // Action #1
    Open Short order at (Fibo(Main chart, Open-Close previous week, Fibo Level = 138.2)[] - (ATR(Main chart,ATRPeriod1)[5] * PriceEntryMult1)) Stop;
        Order valid for BarsValid bars;
        Duplicate trades: allowed; 
        Replacing pending orders: allowed; 
        Stop Loss = SLm * ATR(mATRp);
        Profit target = TPm * ATR(mATRp);

        Trailing Stop = TSm * ATR(mATRp);

        Exit After ExitAfterBars bars;
}




AND THIS ONE FIXED IN ALGOWIZARD HAS 94.35% TRADE SYMMETRY


//--------------------------------------------------------------------
// Trading rule: Long entry (On Bar Open)
//--------------------------------------------------------------------                   
if ((LongEntrySignal
   and Not LongExitSignal)
   and (MarketPosition("Current", MagicNumber, "") is Not Long))
{
    // Action #1
    Open Long order at (Fibo(Main chart, Open-Close previous week, Fibo Level = -38.2)[] + (ATR(Main chart,ATRPeriod1)[5] * PriceEntryMult1)) Stop;
        Order valid for BarsValid bars;
        Duplicate trades: allowed; 
        Replacing pending orders: allowed; 
        Stop Loss = SLm * ATR(mATRp);
        Profit target = TPm * ATR(mATRp);

        Trailing Stop = TSm * ATR(mATRp);

        Exit After ExitAfterBars bars;
}


//--------------------------------------------------------------------
// Trading rule: Short entry (On Bar Open)
//--------------------------------------------------------------------                   
if ((ShortEntrySignal
   and Not ShortExitSignal)
   and (MarketPosition("Current", MagicNumber, "") is Not Short))
{
    // Action #1
    Open Short order at (Fibo(Main chart, Open-Close previous week, Fibo Level = -38.2)[] - (ATR(Main chart,ATRPeriod1)[5] * PriceEntryMult1)) Stop;
        Order valid for BarsValid bars;
        Duplicate trades: allowed; 
        Replacing pending orders: allowed; 
        Stop Loss = SLm * ATR(mATRp);
        Profit target = TPm * ATR(mATRp);

        Trailing Stop = TSm * ATR(mATRp);

        Exit After ExitAfterBars bars;
}

Strats are too large to attache sadly...



MF
#14

Mark Fric

06.12.2022 11:31
ok, I get it now. I changed the Fibo negater to keep the level intact.
b
#15

bentra

06.12.2022 15:07
thanks

Votes: +3

Drop files to upload

or

choose files

Max size: 5MB

Not allowed: exe, msi, application, reg, php, js, htaccess, htpasswd, gitignore

...
Wait please