Simple Coding Help - No Promise.

yasu222

Active Member
#21
I need help on LPT (Line Pair Trading) strategy.

Two parallel lines on Amibroker basic chart -

UPPER LINE - BUY ON CANDLE CLOSE / IMMEDIATE above UPPER LINE .

DOWN LINE - SELL ON CANDLE CLOSE / IMMEDIATE below DOWN LINE.

BUY/SELL TGT = BUY/SELL PRICE + (BUY/SELL PRICE* X%).

NEEDS THE ABOVE LPT STRATEGY TO BE AUTO MATED AND SEND THE ORDERS FROM AMIBROKER TO NEST TRADING PLATFORM.
 

dell

Well-Known Member
#22
In amibroker exploration has 2 parts
1. the condition for which you want to filter rows
2. formatting of the output

as you already know the condition it becomes v simple just equate it to the keyword filter

Code:
Filter=(L < w) AND (H > w);
For formatting check keyword AddColumn in ami help few samples

Code:
AddColumn( Close, "Close", 1.2 );
AddColumn( MACD(), "MACD", 1.4 , IIf( MACD() > 0, colorGreen, colorRed ) );
AddTextColumn( FullName(), "Full name", 77 , colorDefault );

Cheers

:) Happy
thanks for helping , yes i understand it how to create explore code ,
, it solves my problem .............
 
Last edited:
#24
I need help on LPT (Line Pair Trading) strategy.

Two parallel lines on Amibroker basic chart -

UPPER LINE - BUY ON CANDLE CLOSE / IMMEDIATE above UPPER LINE .

DOWN LINE - SELL ON CANDLE CLOSE / IMMEDIATE below DOWN LINE.

BUY/SELL TGT = BUY/SELL PRICE + (BUY/SELL PRICE* X%).

NEEDS THE ABOVE LPT STRATEGY TO BE AUTO MATED AND SEND THE ORDERS FROM AMIBROKER TO NEST TRADING PLATFORM.

The buy sell part is easy, but . . . You will need to find a professional coder for automation projects . . .

And sorry, i will not be able to help you in finding any programmer/coder as for now i do not have any reference to give you.

Cheers

:) Happy


Code:
su = Study("SU", GetChartID() ); 
re = Study("RE", GetChartID() ); 
Buy 	=	Cross(C,su);	
Sell 	=	Cross(re,C);	
Buy 	= 	ExRem(Buy,Sell);	
Sell 	= 	ExRem(Sell,Buy); 
Short	= 	Sell;			
Cover	= 	Buy; 
Plot(re+re-su,"Long Target",colorBlueGrey,styleDashed);
Plot(su+su-re,"Short Target",colorLime,styleDashed);
PlotShapes(Buy+2*Short,colorRed,0,IIf(Buy,L,H),-20);
EDIT: Here's how you use the above code . . .

Draw 2 lines of the chart horizontal or trend lines also will do . . .
Double Click on the lines to open the properties tab, choose the study id
for first line choose re and su for next, once you have thus named the Lines only then the above code will work
 
Last edited:
#25
Really good help, Happy, and don't pretend you are not an expert! :)

I will look into your answer to the first question a little laboriously and then respond. In the mean time let me express something about the 2nd answer.

Fortunately I have been able to write the code for TSL and SL. But this is not working properly because perhaps of the syntax error. Just tell me if the syntax in my IIF line was correct, and if not, the correct way to write it.

Thanks again!
 
#26
2) Sell=IIf (close<=0.998*priceatbuy,1,0);

This line is supposed to sell when the current price is <= 0.998 * buy price and NOT to do anything otherwise. Am I correct? But it is doing nothing at all.

Would be obliged to get help.
Fortunately I have been able to write the code for TSL and SL. But this is not working properly because perhaps of the syntax error. Just tell me if the syntax in my IIF line was correct, and if not, the correct way to write it.
Try this simpler version


Code:
//priceatbuy=BuyPrice;
Sell = Close <= 0.998*priceatbuy;
or

Code:
Sell = Cross(0.998*priceatbuy, close);
but the above will give you an effect of only < and not <=


BTW have you tried using ApplyStop(0,1,0.2);

it should give you the same effect

Cheers

:) Happy
 

KelvinHand

Well-Known Member
#27
Try this simpler version


Code:
//priceatbuy=BuyPrice;
Sell = Close <= 0.998*priceatbuy;
:) Happy
If you are using BuyPrice as priceatbuy
The answer will be Close Price is same as BuyPrice.
The condition is will always 0 and no sell.
for example
Code:
 Close = 1000;
 priceatbuy = BuyPrice = 100;

 Sell := Close <= 0.998*priceatbuy
       := 1000 <= 0.998*1000
       := 1000 <= 998
       := false
However is you set priceatbuy to a fixed value, then you can see the sell condition will work.
So basically your IFF() function is correct except the problem come from priceatbuy.



You can trace your problem yourself by adding this statement :
Title = "Close : " + Close + ", priceatbuy = " + priceatbuy;

OR
use _Trace();
 
Last edited:
#28
Hey Kelvin

Thanks for your Help. :)

Hope we will continue getting your inputs on this thread.


In the above example if we want to use the SL as % of entry price, i feel the easiest option will be to use APPLYSTOP(0,1,%)

For some reasons though if we have to include that condition along with the Sell Statement,

then we should be able to use ---- ValueWhen(Buy,BuyPrice,1);


Once again Thanks for your help,
we all have learned a lot from your posts here at Tj and code shares on the internet.



Thanks

:) Happy


EDIT:
and btw the above commented line in my code should have been \\priceatbuy= your BuyPrice; or something to this effect
it was an error on my part, it did look like a part of the code statement rather than a comment :eek:
 
Last edited:

amibrokerfans

Well-Known Member
#29
dear Happy_Singh and KelvinHand,

i like to know how Valid DIFF_METHODs - PERCENT(%) and POINTS($) can be written in amibroker?

here is two metastock formula using % and $..

1. oscp(1, 25, E, $)
2. zig( CLOSE, 5, % )

can you please translate above two formula to amibroker for example..
 

KelvinHand

Well-Known Member
#30
dear Happy_Singh and KelvinHand,

i like to know how Valid DIFF_METHODs - PERCENT(%) and POINTS($) can be written in amibroker?

here is two metastock formula using % and $..

1. oscp(1, 25, E, $)
2. zig( CLOSE, 5, % )

can you please translate above two formula to amibroker for example..
Need to know the formula.

for oscp, I suppose this is the fomula for %,
you can verify whether the below is same as oscp(%)
http://www.investopedia.com/terms/p/ppo.asp

for zig, not sure. may be this:
http://www.linnsoft.com/tour/techind/zigosc.htm
 
Last edited:

Similar threads