Result of crossing means in the analysis?

Hello, I would like to do a backtest, but before I do it, I would like to get the results of intersection of averages, their dates of occurrence and the maximums that were achieved in 100 consecutive periods in the form of a summary

I do not know how to do it and I cannot find information in this regard (I do not know where to look for it or how)

I'm new, maybe it's simple, but I'm learning and I'm asking for help.

I wrote the formula below, but I don't know how to get the data that interests me.

_SECTION_BEGIN("SMART TEST TRADING SYSTEM ");

Bwolna=EMA(C,50);
Bsuper=EMA(C,100);

Buy=Cross(Bwolna, Bsuper);
Sell=Cross(Bsuper,Bwolna);
Max100=HHV(Buy, -100);
AddColumn(Buy, "value cross");
AddColumn(Buy, "date cross");
AddColumn(Max100, "value Max");
AddColumn(Max100, "data Max");

Filter = C>0 and buy=1 and max100>0;
_SECTION_END();

To display value of moving average you should use:

AddColumn(Bwolna, "Bwolna at cross");
AddColumn(Bsuper, "Bsuper at cross");

Highest high value for last 100 bars is:

Max100 = HHV( High, 100 );

Also Filter code should be just

Filter = buy; 

as close is always > 0 and max100 is also > 0.

I think I asked the question wrong.
I mean the value and date of the rate at the intersection of two averages

Suppose in a month the averages crossed 10 times from bottom to top - the golden cross (which gives us 10 points of intersection).
I would like to have 10 records and in each of them information
about the closing price at the crossing point,
the crossing date and what was the maximum closing price after 100 periods after the crossing date
And similarly for the black cross (intersection of the medium-fast from top to the bottom of the medium-slow)

_SECTION_BEGIN("SMART TEST TRADING SYSTEM ");
/// @link https://forum.amibroker.com/t/result-of-crossing-means-in-the-analysis/26355/5
Bwolna=EMA(C,50);
Bsuper=EMA(C,100);

Buy=Cross(Bwolna, Bsuper);
Sell=Cross(Bsuper,Bwolna);

dt = DateTime();

barsBuy = BarsSince(Buy)+1;
MaxBuy = HighestSince(Buy, C);

AddColumn(ValueWhen(Buy,C), "value up cross");
AddColumn(ValueWhen(Buy,dt), "date up cross", formatDateTime);
AddColumn(MaxBuy, "value Max up");
AddColumn(Ref(dt,-HighestSincebars(Buy, C)), "data Max up", formatDateTime);

Filter = barsBuy == 100;
_SECTION_END();
1 Like

Thank you very much, it works fine.
I have a question, how to assign a constant value to tickers from the watchlist. So that the analysis can perform calculations for each ticker separately.
Rate difference x constant value (each ticker has a different constant value)

Hello, I have such a nice code. Additionally, I need to calculate the max / min that occurs before or after the cross is formed.

Is there any function that can find max / min and how to find it (some loop or something?)

How to write such a code?

I need to know this value for analysis.

_SECTION_BEGIN("SMART TEST TRADING SYSTEM ");
/// @link https://forum.amibroker.com/t/result-of-crossing-means-in-the-analysis/26355/5
Bwolna=EMA(C,50);
Bsuper=EMA(C,100);

Buy=Cross(Bwolna, Bsuper);
Sell=Cross(Bsuper,Bwolna);

dt = DateTime();

barsBuy = BarsSince(Buy)+1;
MaxBuy = HighestSince(Buy, C);

AddColumn(ValueWhen(Buy,C), "value up cross");
AddColumn(ValueWhen(Buy,dt), "date up cross", formatDateTime);
AddColumn(MaxBuy, "value Max up");
AddColumn(Ref(dt,-HighestSincebars(Buy, C)), "data Max up", formatDateTime);

Filter = barsBuy == 100;
_SECTION_END();

The code already includes the function that gets highest close since cross (Buy signal):

HighestSince(Buy, C);

HighestSince (Buy, C), is the highest closing value since the intersection over a period of e.g. 100 periods (bar). Based on this function, it identifies the first potential exit from the position.

And now I'm looking for an trigger to enter. For me, the trigger to enter will be the first correction after the crossing or the last high or low before the crossing. (depends on the direction in which I trade)

The HighestSince function will return the highest values ​​in 100 periods (bars) and there may be several smaller ones along the way and I'm interested in the closest cross (according to the rule, higher lows and higher peaks, eliot waves or ZIG ZAG)
I assume I should look for the peaks in the loops and see if they are higher than the cross. The first higher peak or dimple is what I look for behind or before the cross.

How to write such a code?

I need to know this value for analysis.

When can i expect to reply?

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.