Simple Coding Help - No Promise.

I have some idea about trading i think its work good

Logic is below..

Three moving avarage

First Moving avg 5 Day
second Moving avg 25 Day
Third Moving avg 50 Day



Buy If 5 moving avg cross to 50 up side buy

Exit If 5 moving avg cross to 25 down ( Buy exit not sell )

Buy agin if 5 Moving avg cross to 25 up ( Buy only if 5 Moving Avg is greater than 50 Moving Avg )

Sell If 5 moving avg cross to 50 down side sell

Exit If 5 moving avg cross to 25 up ( Sell exit not Buy )

Sell agin if 5 Moving avg cross to 25 Down ( Sell only if 5 Moving Avg is lower than 50 Moving Avg )

Please try these i think its very help full for all

thanks
Code:
M5=MA(C,5);
M25=MA(C,25);
M50=MA(C,50);

Buy=Cross(M5,M50);
Short=Cross(M50,M5);
Sell=Cross(M25,M5);
Short=Cross(M5,M25);

// Sprinkle ExRem's as necessary
Hmmm.... The triple barrel system

AFAICT, prime multiples would work better than non-prime numbers.

25 would peform better if it is replaced with a prime number Say 23
Similary 53 would be better than instead of 50.

Also, the gap between fast average and slower average
 

TracerBullet

Well-Known Member
TracerBullet,

POINT 1)
augubhai wanted code that does not use loops. My answer about hint about complexity was confined to that.

POINT 2)
I doubt that Happy Singh has ever called himself as "owner" of the thread.
Number of posts by me in this thread: 284.
Number of posts by Happy Singh: 232.
Number of Posts by TracerBullet: 1

POINT 3)
Pls don't meddle with freedom of expression of people who actually bother to answer the questions that are posted here ....
MM
1) What is the point of saying below ? I have seen this a few times now. Why you keep telling people what is and is not allowed in this thread?
and it is certainly doesn not fall in "Simple Coding Help" thread
2) And what ? Good that you try to help, it does not change the meaning of your last post. I dont need to make biodata of my contribution and anyway its not relevant.

3) Yes, just as well i have mine too. You bother sometimes without actually helping ..

Anyway, This certainly does not fall under "Simple Coding help" thread :)
No more arguments from me as it can get silly, good day.
 
Sorry,

I did not state my requirement clearly earlier.

I want to find
1. the count of bars (Bar A to B in image) when the high was equal or greater than the chosen bar high.
2. the count of bars (Bar A to C in image) when the high is equal or greater than the chosen bar high.

I do not want to use loops (for/while) for this. I want to do this using only array functions.

(Hope the requirement is clear now :eek:)

Hello

Any specific reasons for not wanting to use loops . . .

If the charts are to be used only for visually interpretation then you can limit the loop only to visible candles.

On a side note, I know you are a functional AB coder,
so assuming you can easily put together a code to count bars between two highs/lows using a loop.

Happy :)
 

augubhai

Well-Known Member
Hello

Any specific reasons for not wanting to use loops . . .

If the charts are to be used only for visually interpretation then you can limit the loop only to visible candles.

On a side note, I know you are a functional AB coder,
so assuming you can easily put together a code to count bars between two highs/lows using a loop.

Happy :)

Hi Happy,

I am trying to backtest different scenarios with multi-year data of multiple scrips. For performance reasons, I would prefer avoiding loops.

Vaguely, I am hoping for something like a way to refer the current bar data in ValueWhen()...
 

TracerBullet

Well-Known Member
Hi Happy,

I am trying to backtest different scenarios with multi-year data of multiple scrips. For performance reasons, I would prefer avoiding loops.

Vaguely, I am hoping for something like a way to refer the current bar data in ValueWhen()...
i dont know much about how AB works, so correct me if wrong - but anyway some things to check until you get a proper answer -

1) Maybe can you put some limits on how far the loop can go ? Will you loop for every bar or only some bars like pivots?

2) Have you seen this type of loop causing slowdowns in past? Many times premature optimization (unless backed by experience) is waste of time as bottleneck can be somewhere else.

3) In normal language, running a loop for few bars should probably be faster than processing the condition for each bar in array. But it seems arrays are faster in AB as its loops will be interpreted while each array operation can be done quickly by compiled command.
So, Is ADK faster? Perhaps loops wont be expensive with compiled plugins?
 

augubhai

Well-Known Member
i dont know much about how AB works, so correct me if wrong - but anyway some things to check until you get a proper answer -

1) Maybe can you put some limits on how far the loop can go ? Will you loop for every bar or only some bars like pivots?
Yes, skipping bars while looping is an option.

2) Have you seen this type of loop causing slowdowns in past? Many times premature optimization (unless backed by experience) is waste of time as bottleneck can be somewhere else.
Yes, I have faced this issue many times. The system hangs if the code in the loop is complex - both while backtesting as well as on live charts. Simple code will work.

Maybe the issue is with my setup. I am using Amibroker 5.40 on an old laptop for the backtests.

3) In normal language, running a loop for few bars should probably be faster than processing the condition for each bar in array. But it seems arrays are faster in AB as its loops will be interpreted while each array operation can be done quickly by compiled command.
So, Is ADK faster? Perhaps loops wont be expensive with compiled plugins?
I don't know about compiled plugins. But I need to frequently modify the code while backtesting different scenarios. I don't know if recompiling plugins would be quick enough.

So, looping is the alternative that I will have to use if I don't get a solution with array variables....
 

TracerBullet

Well-Known Member
Yes, skipping bars while looping is an option.



Yes, I have faced this issue many times. The system hangs if the code in the loop is complex - both while backtesting as well as on live charts. Simple code will work.

Maybe the issue is with my setup. I am using Amibroker 5.40 on an old laptop for the backtests.



I don't know about compiled plugins. But I need to frequently modify the code while backtesting different scenarios. I don't know if recompiling plugins would be quick enough.

So, looping is the alternative that I will have to use if I don't get a solution with array variables....
ok, still try to write basic code and check if it hangs.

i have never done backtest on all data, but atleast in live afl and in exploration i have plenty of loops for pivots etc and 5 charts at same time. There is no slowdown. Hangs usually happen if there is a bug and you have infinite loop.

If you write basic code, you can try to profile it ( ie get difference in start and end time of different functions) and check where is the bottleneck. Then you can try to optimize it.

As an example, below is snippet from my chart afl with Double loops. CPU usage from AB is minimal. It does not solve your problem, but i am just saying loops are not necessarily bad

Code:
for( i = BarCount-1; i > BarCount-LOOKBACK && i>=0 ; i-- ){

	HLSatisfied 	  = False;	
	closeSatisfied  = False;
	isPivot		  = False;

	if( (PH[i] || PL[i]) && ( H[i]-L[i] >= ATR21[i] * WRB_ATR_MIN )  ){
																	// Is WRB ? WRB If Bar length is some ATR multiple
		isWRBPivot = False;

		for( j=i+1; j<BarCount && (j-i) <= WRB_INSIDEBARS_MIN; j++ ){
			if( H[i] < H[j] || L[i] > L[j] )					// Check Inside Bars
				break;
			else if( j-i == WRB_INSIDEBARS_MIN ){				// Allow pivots within WRB MC if enough Inside bars exist
				isWRBPivot = True;
				break;												
			}
		}

		if( isWRBPivot )											// MC/WRB Pivot, Ignore H/L and close condition
			continue;
	}

	if( PH[i]  ){
		for( j=i+1; j<BarCount && (j-i) <= PIVOT_CLOSECHECK_BARS; j++ ){
			if( !HLSatisfied && L[j] < L[i]  )
				HLSatisfied = True;
			if( !closeSatisfied && C[j] < C[i] )
				closeSatisfied  = True;
			
			if( HLSatisfied && closeSatisfied  ){
				isPivot = True;
				break;
			}

			if( H[j] > H[i] )										// PH broken without satisfing condition
				break;
			if( PL[j] )											// PL found, but this PH is not yet confirmed - unmark PL
				PL[j] = False;
		}
		
		if( ! isPivot   ){										// Lower Low and Lower Close not found
			PH[i] = False;
		}
	}

	HLSatisfied 	  = False;	
	closeSatisfied  = False;
	isPivot		  = False;	

	if( PL[i]  ){
		for( j=i+1; j<BarCount && (j-i) <= PIVOT_CLOSECHECK_BARS; j++ ){
			if( !HLSatisfied && H[j] > H[i]  )
				HLSatisfied = True;
			if( !closeSatisfied   && C[j] > C[i] )
				closeSatisfied  = True;

			if( HLSatisfied && closeSatisfied  ){
				isPivot = True;
				break;
			}

			if( L[j] < L[i] )										// PL broken without satisfing condition
				break;
			if( PH[j] )											// PH found, but this PL is not yet confirmed - unmark PH
				PH[j] = False;
		}
		
		if( ! isPivot   ){										// Higher High and Higher Close not found
			PL[i] = False;
		}
	}
}
 

john302928

Well-Known Member
Hi
Below is the coding for Daily Top gainers. Could you modify this code to apply it in hourly time frame and 5 min time frame. Thanks in advance

C1=Ref(C,-1);
CHANGE=100*(C-C1)/C1;//Change Percentage
Filter=Change;
AddColumn(CHANGE,"% change");
AddColumn(Close,"close");
AddColumn(Volume,"volume");
 

john302928

Well-Known Member
Any help bros
Hi
Below is the coding for Daily Top gainers. Could you modify this code to apply it in hourly time frame and 5 min time frame. Thanks in advance

C1=Ref(C,-1);
CHANGE=100*(C-C1)/C1;//Change Percentage
Filter=Change;
AddColumn(CHANGE,"% change");
AddColumn(Close,"close");
AddColumn(Volume,"volume");
 

Similar threads