scoreNoRotate, as documented, prevents new trades, was: Why rotational system is not trading

Someone, help me why this system is not trading?

MaxPositions = 4;
SetOption("MaxOpenPositions", MaxPositions );
SetOption("WorstRankHeld", MaxPositions + 2 );
//SetPositionSize( 100 / MaxPositions, spsPercentOfEquity );
PositionSize = 150; // invest $150 into single trade
// trade on next day open
SetTradeDelays( 1, 1, 1, 1 );
BuyPrice = Open;

SetBacktestMode( backtestRotational );

// offsetting by large positive number
// makes sure that our score is always positive and we don't enter short trades

Score = 10000 - ROC( C, 252 );
rotation = C>5;
PositionScore = IIf( rotation, Score, scoreNoRotate );

Filter=1;
AddColumn( Close , "Close", 1.2, colorDefault, colorDefault) ;
AddColumn( PositionScore , "PositionScore", 1.2, colorDefault, colorDefault) ;
AddColumn( rotation , "rotation", 1, colorDefault, colorDefault) ;

@Mactoub,
Welcome to the forum. You would be well-advised to study the following page:
https://forum.amibroker.com/t/how-to-use-this-site/182

We also use code tags </> to wrap our code so it's easier for others to test. In addition it helps to avoid typos in the code.

I copied your supplied code into Formula Editor and ran it as a backtest on a watchlist comprised of 29 ETFs using the Worden TC2000 database from 2018-01-01 to 2019-03-21 and it generated 23 trades. It appears to be working.

1 Like

Hello ghanson,
thank you for answer. I backtested it on NYSE all symbols, but it is not generated trades. If you see the file attached, there is not open possitions. If you see fist ticker chosen ABEV it date 03.02.2010 - the price was about $3.4 , maybe this is the problem because there must be just tickers with Close >5........Rotational

Thank you

@Mactoub,
Post your code if you want someone to help you correct the code. I was new at one time and learned (the hard way) that to get help on this forum you have to put in some effort to solve your own problem. This board is loaded with incredibly smart coders who are willing to help a guy provided he is asking for help and not asking somebody to write his code.
Is the code you posted originally the entire code in your program? What are the settings you're using in your backtest? Do you see how this can become a guessing game and waste a lot of time?
As a double-check I just copied your code into AFL and ran it against my ETF set and it produced 23 trades. I changed the dates, re-ran the backtest and it produced different trades for the non-overlapping time period.
Check your settings in the Analysis windows.

ghanson
Thank you for answer. Believe me I put in much effort to solve this code. I am working on it over week, googling, read the forums, but not able to solve it. This is why I put my code here.
I dont know what can I do more. Here is my code and mistake explained....
Simply this code is not working on shares, but i bealive it is working on your database.
But still I dont know where the problem is, I am beginner in programming.....

Anyway thank you for your time.

@Mactoub, you can try to save all your analysis settings in a .apx file (Analysis Project) and post it so for other users it will be possible to replicate your environment.

@Mactoub,
This is not goodbye, don't give up the fight! Help is here.
Follow @beppe 's advice and create an APX which lets others see precisely what environment you're testing within. As @Tomasz says, "AmiBroker works", thus we know it's your code which isn't [working]. And that is good news because it means there is a solution.

1 Like

beppe and ghanson,
Thank you for answer I apreciate that.
Here is possible to download apx file: https://uloz.to/!33CyatLP2mUZ/examplerotational-apx

Maybe I found the reason why there was not trades:
If I change: "rotation = C>5;" to "rotation = true;" - there are trades now. But I need to take the to rotational system just tickers which price is > 5. There must be some other code how to solve it, but unfortunately I do not have idea.

Original code here:
MaxPositions = 4;
SetOption("MaxOpenPositions", MaxPositions );
SetOption("WorstRankHeld", MaxPositions + 2 );
//SetPositionSize( 100 / MaxPositions, spsPercentOfEquity );
PositionSize = 150; // invest $150 into single trade
// trade on next day open
SetTradeDelays( 1, 1, 1, 1 );
BuyPrice = Open;

SetBacktestMode( backtestRotational );

// offsetting by large positive number
// makes sure that our score is always positive and we don't enter short trades

Score = 10000 - ROC( C, 252 );
rotation = C>5;
PositionScore = IIf( rotation, Score, scoreNoRotate );

Filter=1;
AddColumn( Close , "Close", 1.2, colorDefault, colorDefault) ;
AddColumn( PositionScore , "PositionScore", 1.2, colorDefault, colorDefault) ;
AddColumn( rotation , "rotation", 1, colorDefault, colorDefault) ;

Thank you

I downloaded the .apx and tested your formula.
As in my the previous tests (also as reported by @ghanson) I got a list of trades (analysis was done with the line rotation = C>5; enabled).

So it seems that there is nothing strange in the code and/or in the environment. Maybe something in the data?

Let's see if someone else can figure out this issue.

1 Like

@Mactoub,

  1. Wrap your code in code tags. It makes it easier on the people who are trying to help you.
    See https://forum.amibroker.com/t/how-to-use-this-site/182 and thoroughly read the "Enter the AFL code properly" section.
    I also advised this earlier but you haven't read it yet. Please do so.
  2. Use a different list of tickers and see if you get trades.

I have tried to backtest in another symbol list - Russell 3000 and the result is same - no trades. If I try to list of indices it is working. It seems that it is not working for shares. Maybe some wrong setup, but I do not know.....

It is pretty obvious from detailed log. No mystery at all. Works as documented. You see you've got first symbol (ABEV) that has score 1e+011. That is scoreNoRotate value and it prevents rotation at all, i.e. prevents trading ON ALL SYMBOLS as per documentation
http://www.amibroker.com/f?enablerotationaltrading

the score equal to scoreNoRotate constant means that already open trades should be kept and no new trades entered

Your code is simply wrong because if you have just ONE symbol which price is lower than 5 it would BLOCK everything else.

Just remove scoreNoRotate. That is what is wrong with your code.

Correct code would be:

PositionScore = IIf( rotation, Score, 0 );
2 Likes

Hy guys, thank all of you for answer and to be patient.

@Tomasz, I have a question to clarify this situation further. What happens if the ScoreNoRotate is assigned to a stock that is not the first one?

Let's suppose I have a rotation with 20 tickers, and I decide to set the scoreNoRotate to the 16th ranked ticker based on its specific conditions.

In this case, the rotation will still happen for the higher ranked tickers (first 15), and the following (5) positions are kept (blocked - no more rotation) or no rotation at all will happen, retaining all the 20 existing positions (so there will no change to the portfolio)?

1 Like

scoreNoRotate (for this exact purpose) has numeric value of 1e11 (100000000000), so it always lands on top of ranked list (regardless which symbol generated it) and prevents trading on all symbols.

3 Likes