Help to create a new index with my simple formula

i want to create a new index with the formula that the price of a rising stock times its volume and the price of a falling stock times its volume

i tried using addtocomposite but the result is not correct. please help me to find the solution for this idea


Buy = Sell = 0;
Filter = 0;


AddToComposite(IIf(C>Ref(C,-1),C,0),"~upprice","C");
AddToComposite(IIf(C<=Ref(C,-1),C,0),"~downprice","C");

upprice=Foreign("~upprice","C");
downprice=Foreign("~downprice","C");


AddToComposite(IIf(C>Ref(C,-1),V,0),"~upvol","V");
AddToComposite(IIf(C<=Ref(C,-1),V,0),"~downpvol","V");

upvol=Foreign("~upvol","V");
downpvol=Foreign("~downpvol","V");

up = upvol*upprice;
down = downpvol*downprice;
Plot(up,"Up",colorBlue);
Plot(down,"down",colorRed);


GraphLabelDecimals = 0;

1 Like

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.

You have not specified the context. Also you have not said what is not correct.
So in the guessing game, this could be why.

I run scan first and plot it on chart as below but values seem not correct

image

Is it possible on this ?

AddToComposite( array, ''ticker'', ''field'', flags = atcFlagDefaults )

atcFlagDeleteValues = 1 - deletes all previous data from composite symbol at the beginning of scan (recommended)

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.