I am trying to add two option prices which I have done it but now I want to convert it a symbol for which I am using Add to composite. But the prices are not coming correct after using Add to composite.
symbol1 = ParamStr("instrument1","BANKNIFTY02MAY1929500CE.NFO");
symbol2 = ParamStr("instrument2","BANKNIFTY02MAY1929500PE.NFO");
close1 = Foreign(symbol1,"close");
close2 = Foreign(symbol2,"close");
lclosefinal = close1+close2;
AddToComposite(Lclosefinal,"~Straddle","X");
Plot(Foreign("~Straddle","X"),"Straddle",colorBlack,styleLine);
AFL Function Reference - ADDTOCOMPOSITE
AddToComposite function also detects the context in which it is run
(it works ONLY in scan mode, unless atcFlagEnableInBacktest or atcFlagEnableInExplore flags are specified) and does NOT affect composite ticker when run in Indicator or Commentary mode, so it is now allowed to join scan and indicator into single formula.
Check the context and set the required Flags or run in the correct context.
Otherwise, the code runs correctly.
Hello Travick, right now I am running it in scan mode. As soon as I scanned, this symbol was generated but with wrong prices
It seems to work fine here, why don't you enable atcFlagEnableInExplore and use the Exploration to debug as well.
( delete old symbol )
I mean add 3 columns with prices from base and whatever you get from the Foreign symbols and post a screenshot.
Info tab also reccomends (801) Pad & Align, did you check for holes etc?
Travick, Can you please tell me why I am not able to explore ~straddle ?
I want to compare Lclosefinal and ~ straddle because they both should be the same
If my code is wrong, please can you write the code by which I can run eploration , so that I can give you the screenshot
You should use Flags like this in ATC
... ,atcFlagDefaults | atcFlagEnableInExplore );
And you cannot access a symbol by the name like that in Error 31,
use Foreign() Fn like those used above.
Delete the previous symbol, and make sure this code runs only once.
If you are going to run in a few times, then ATC will keep adding to it.
Generally, this should not happen with the Default Flag as it has Reset but just read the docs as a double check but can occur with multiruns in the same scan.
(OR Better yet, run Exploration with Symbol Filter menu set to current symbol )
I ran the code and here is the exploration result
You are running ATC in more than one run, look at the symbol column, you have to run ATC only once and ensure in your code also the same thing. If it runs multiple times within the same scan or Explore, of course it will add it cumulatively.
check for data holes as well.
1 Like
I am feeling a bit sorry as you have tried your best explaining it. But I still don't know why its not working.
Would you mind coming to anydesk or team viewer and see why its not working ?
Thanks Sir