Australian (ASX) Stock Market Forum

Amibroker FAQ

Back to time periodicy...

I am now trying to find every fortnight. The code below when plotted does the job fine, however when put into a trading system no trades are taken. I don't know why.

Code:
// Days of the week
timeDayName = DayOfWeek();

// Every Friday
checkEndWeek = timeDayName < Ref( timeDayName, -1 );

// Every fortnight
checkEndWeekCount = Cum( checkEndWeek );
checkEndFortnight = checkEndWeek AND ( checkEndWeekCount % 2 == 0 );

This is for a rotational trading system and after running the backtest with detailed log it shows scoring weekly but no trades are taken which is a clue I guess. Any help appreciated.

I think you are getting what you want, but just so you know that you are identifying Monday or the Start of the Week not the "EndWeek" or end of a week (usually a Friday). Your variables are all named "End...." implying to me at least a Friday or end of a week.
 
And what list of ETFs are you applying it to.

The problem occurs regardless of what ticker I apply my code to with the exception of the XAO index ticker. I think the issue is with the variety of non-trading days that occur across a basket of ETF's or stocks.
 
I think you are getting what you want, but just so you know that you are identifying Monday or the Start of the Week not the "EndWeek" or end of a week (usually a Friday). Your variables are all named "End...." implying to me at least a Friday or end of a week.

This is just naming convention in my code and is to do with trade delays etc. I can see how it may be confusing. I check for signals on Friday, trade on Monday.
 
Why is my bar counter not working?:rolleyes:

Code:
// Bar counter
bars = 0;
for( i = 0; i < BarCount; i++ )
{
  if( bars > 0 ) bars[i++];
  if( Buy ) bars= 1;
  if( Sell ) bars= 0;
}

I only want to count bars while I'm in a trade.
 
Why is my bar counter not working?:rolleyes:

Code:
// Bar counter
bars = 0;
for( i = 0; i < BarCount; i++ )
{
  if( bars > 0 ) bars[i++];
  if( Buy ) bars= 1;
  if( Sell ) bars= 0;
}

I only want to count bars while I'm in a trade.

Dear rb, have you considered asking your questions on the most active AmiBroker user forum? There are many above average to excellent programmers as well as TJ (AB creator) himself often answering questions by posters. I believe you are more likely to find assistance on that forum.

Look it up and register, and I will post an answer to your latest question if one of the other more expert coders doesn't respond.
https://groups.yahoo.com/neo/groups/amibroker/conversations/messages

Good luck, hope to see you on the other side.

PB
 
Why is my bar counter not working?:rolleyes:

Code:
// Bar counter
bars = 0;
for( i = 0; i < BarCount; i++ )
{
  if( bars > 0 ) bars[i++];
  if( Buy ) bars= 1;
  if( Sell ) bars= 0;
}

I only want to count bars while I'm in a trade.


You code is not correct that's why it is not working.

First of all Buy and Sell variables are arrays! You need to use subscript operator in order to access elements of an array.

Secondly use flag initialized to false:
if buy then flag is set to true, if sell flag is set to false.
If sell the reset bars counter.
In addition add if statement checking for true flag and where you count bars in trade;

last but not least create barsarr variable to store bars counter at each array index.
Code:
barsarr[i] = bars;

The next thing is: you don't need loop as you can make bar counter with existing functions Flip() and BarsSince().
 
You code is not correct that's why it is not working.

First of all Buy and Sell variables are arrays! You need to use subscript operator in order to access elements of an array.

Secondly use flag initialized to false:
if buy then flag is set to true, if sell flag is set to false.
If sell the reset bars counter.
In addition add if statement checking for true flag and where you count bars in trade;

last but not least create barsarr variable to store bars counter at each array index.
Code:
barsarr[i] = bars;

The next thing is: you don't need loop as you can make bar counter with existing functions Flip() and BarsSince().

Correction:
If sell then reset bars counter.

In addition add if statement checking for true flag and where you count bars in trade;
By that one it is meant like this
Code:
if( flag )
    bars++;
 
If you are referring to me then yes, my problem is fixed. Thanks for your help trash. I actually used a nested loop, the primary loop triggered the buy and recorded the bar count, then nested under that was the sell which was either on a signal or a maximum bar count (timed exit).
 
Is you loop problem solved actually? If you are just waiting for copy&paste ready codes then Portfoliobuilder and me will save our time responding next time.

OT to trash

I am very impressed by your Custom Chart Trading plugin, I was looking for it for a long time. Is it possible to buy it?

thanks

sorry for the OT here
 
Say I buy today and I want to sell if any subsequent bar's close is less than the low of the bar when the buy signal is created. How to do that please?
 
GB - use a nested loop. In the first loop which triggers a Buy = true, store the low L[j]. Then in the sub loop keep iterating and checking if the current close C[k] < L[j]. If yes, Sell = true.

See how you go!
 
Top