Simple Coding Help - No Promise.

xsis

Active Member
thanks happy bhai!
actually i change the TF quite often and for different stocks it diff. so i thought that if it could be tweaked using multiTF (timecompress & timeexpand)
btw - can it be done tht way??
Go to Database settings >> Intraday settings

Change the start time to 9:00 or 9:10 and not 9:15,
now the first 10 minutes bar will close at 9:20.

Also adjust the time in the AFL

Happy :)
 

nac

Well-Known Member
Is this possible to write condition for "buy when the condition is not met")?
For eg:
TOUCH20 = H > EMA(C,20) AND L < EMA(C,20);
FILTER = TOUCH20;
ADDCOLUMN (TOUCH20,"TOUCH20");

BUY = When it's not TOUCH20. // like False(TOUCH20);
 

nac

Well-Known Member
There is something wrong with this code. The trade signals, it generates are wrong.

Can you please tell/correct what's wrong?

TOUCH20 = H > EMA(C,20) AND L < EMA(C,20);
dd = DaysSince1900();
DIFF20 = ValueWhen( TOUCH20, dd ) - ValueWhen( TOUCH20, dd, 2 );
B20 = DIFF20 > 50 AND H < EMA (C,20);
S20 = H >= EMA (C,20);
SH20 = DIFF20 > 50 AND L > EMA (C,20);
C20 = L <= EMA (C,20);

Buy = B20;
Sell = S20;
Short = SH20;
Cover = C20;

Filter = TOUCH20;
AddColumn (TOUCH20,"TOUCH20");
AddColumn (DIFF20,"DIFF20");
 

trash

Well-Known Member
No, the last code, the one with buy parameters, was my doing. :lol: He helped me with the MA touch thing (and probably will help me with this buy stage too, I just didnt receive the answer yet, must be busy).

And I know it must be upseting when someone comes with some basic questions that may have been answered if he had read the guide. But I'm quite an pro-active person, and I only bother others if Im really having difficulties. I've read the reference guide many times, but I think I understood it all wrong. For example:

1 - I dont know what happens when the code is writen without arguments, because i didnt find any example in the guide i.e. "If you write function (), thats whats gonna happen... but if you write function (something), its gonna work this way..."

2 - I'm researching about how to understand and write those "for(i = 0, i < barcount - 1 , i++)" in C++ ebooks because it also isnt really well explained in the guide.

Unfortunatelly, the guide isnt really too clear to complete beginners. I saw some codes where it appeared like this:

Sell = 0;
Applystop(...);

So I tried doing it in my code, but the result was all the same.

Anyway, I'll study the codes you showed me and see if I can get better results.
Thanks, Trash!! :clap::clap:
1- it is all explained there in regards to Applystop. I have given to you three links. Two of those three link is all you need. So actually all is to be found in the guide and knowledge base. C'mon. Enough with excuses. You have a big roundly formed head on top of your body. That head has quite some content as every other human head, I suppose. Use it.

2- 'for' loop is general case in programming. If you want the author of the program to teach you how to program and about what every bit of possible general code line does mean then he would need to write another thousands of sites of help although there are already books about how to program available. But even for beginners all is available. If you know how to use Excel and how it works then also you already know how to apply AFL. It is not much different. And for further research there are search engines. Help does have search too.

Anyway I have given you three links and one code example. It's all you need to use to get Applystop drawn.

Also in one of those links there is clearly mentioned

1 - regular exit
2 - max. loss
3 - profit target
4 - trailing
5 - n-bar stop
6 - ruin stop

So general Exit is Sell == 1 or just Sell. This means that in order to draw i.e. SL and TGT shapes you need to use
SL = Sell == 2;
and
TGT = Sell == 3;
and so on.
Instead of just PlotShapes( Sell*shapeSmallDownTriangle,....
This is only needed for plotting.

Pretty clear actually.

Then I have given this link (already shown previously) where there are two examples doing the same thing.
http://www.amibroker.com/kb/2007/03/24/how-to-plot-a-trailing-stop-in-the-price-chart/

Now next thing to do is to adjust some code.

Unfortunatelly, the guide isnt really too clear to complete beginners. I saw some codes where it appeared like this:

Sell = 0;
Applystop(...);
?
Since there is no general Sell for exit (if not wanted) then Sell has to be set to zero because ApplyStop already is an exit procedure that sells at a stop.
Of course you can add regular Sell condition to Applystop too instead of Sell = 0; But if there is only stop exit wanted by the code developer then Sell is just zero. Not sure what's the difficulty.
 
Last edited:
1- it is all explained there in regards to Applystop. I have given to you three links. Two of those three link is all you need. So actually all is to be found in the guide and knowledge base. C'mon. Enough with excuses. You have a big roundly formed head on top of your body. That head has quite some content as every other human head, I suppose. Use it.

2- 'for' loop is general case in programming. If you want the author of the program to teach you how to program and about what every bit of possible general code line does mean then he would need to write another thousands of sites of help although there are already books about how to program available. But even for beginners all is available. If you know how to use Excel and how it works then also you already know how to apply AFL. It is not much different. And for further research there are search engines. Help does have search too.

Anyway I have given you three links and one code example. It's all you need to use to get Applystop drawn.

Also in one of those links there is clearly mentioned

1 - regular exit
2 - max. loss
3 - profit target
4 - trailing
5 - n-bar stop
6 - ruin stop

So general Exit is Sell == 1 or just Sell. This means that in order to draw i.e. SL and TGT shapes you need to use
SL = Sell == 2;
and
TGT = Sell == 3;
and so on.
Instead of just PlotShapes( Sell*shapeSmallDownTriangle,....
This is only needed for plotting.

Pretty clear actually.

Then I have given this link (already shown previously) where there are two examples doing the same thing.
http://www.amibroker.com/kb/2007/03/24/how-to-plot-a-trailing-stop-in-the-price-chart/

Now next thing to do is to adjust some code.



?
Since there is no general Sell for exit (if not wanted) then Sell has to be set to zero because ApplyStop already is an exit procedure that sells at a stop.
Of course you can add regular Sell condition to Applystop too instead of Sell = 0; But if there is only stop exit wanted by the code developer then Sell is just zero. Not sure what's the difficulty.
First thing, I want to thank you for all your help. You really helped me a lot. I never questioned that. You gave plent of examples. But at the time you them to me, I didnt understand half of it. Today I can grasp it a little more and be able to do something with it.

Now about the overall codes. For you, who already has a great knowledge in programing, the reference guide must be really simple to understand. But for me, who had zero knowledge in programing since yesterday, it's really complicated.

Actually, I got my backtest working after just changing the amount parameter in the applystop function. Instead of 100, I put like this:

StopLoss = 20 * ticksize; //each tick is 5 points

It worked! Thank you again!


Now I'm just having problems with the plot of Buy/SL/TP lines, but Ill keep trying.

Anyway, thanks again! Im really glad for all the help. Gonna keep studying. :thumb:
 
Guys, I activate the option: ACTIVATE STOPS IMMEDIATELY. I understood that after entering the trade, it checks:

1 - if the low activate the stop loss. If not...
2 - it checks if the high activate the take profit.

Actually, is there a way to make only the first check true? I mean:

1 - check if the low activate the stop loss in the entry bar...
2 - check if the high activate the take profit only after the entry bar.

What do you think? The reason I want it like this is because I want the backtest to assume the worst possible scenario. Since its EOD data, I can't know for certain if the high of the candle was achieved after I entered in the trade. So I want to assume it made the high (takeprofit) before the entry signal (but I want to assume, also, that the StopLoss was achieved after the entry signal).

Thanks!!!

EDIT: I just found the SETTRADEDELAYS function. I think thats the way to go.

But there are two parameters in the sell function. Is there a way to specify, by settradedelay, which is which i.e sell stoploss and sell take profit?
 
Last edited:

trash

Well-Known Member
Guys, I activate the option: ACTIVATE STOPS IMMEDIATELY. I understood that after entering the trade, it checks:

1 - if the low activate the stop loss. If not...
2 - it checks if the high activate the take profit.

Actually, is there a way to make only the first check true? I mean:

1 - check if the low activate the stop loss in the entry bar...
2 - check if the high activate the take profit only after the entry bar.

What do you think?

Thanks!!!

EDIT: I just found the SETTRADEDELAYS function. I think thats the way to go.

But there are two parameters in the sell function. Is there a way to specify, by settradedelay, which is which i.e sell stoploss and sell take profit?
If it is related to applystop just do it this way as shown
http://www.traderji.com/amibroker/90119-simple-coding-help-no-promise-152.html#post961745

The example covers scenarios 1 and 2 of ApplyStop reference guide in provided link http://www.amibroker.com/guide/afl/applystop.html‎

Don't use SetTradeDelays for ApplyStop.


And in general don't use different values (for buy, sell, short, cover) in SetTradeDelays. If you want to use different delays for entry/exit then use Ref() instead.
 
If it is related to applystop just do it this way as shown
http://www.traderji.com/amibroker/90119-simple-coding-help-no-promise-152.html#post961745

The example covers scenarios 1 and 2 of ApplyStop reference guide in provided link http://www.amibroker.com/guide/afl/applystop.html‎

Don't use SetTradeDelays for ApplyStop.


And in general don't use different values (for buy, sell, short, cover) in SetTradeDelays. If you want to use different delays for entry/exit then use Ref() instead.
Thanks Again, Mr. Trash. I saw the code, but i didnt understand what it did. Now I can apreciate its functionallity. I dont know how it work yet, but I was able to implement it in my code.

Thank you very much! :thumb:
 

Similar threads