Wednesday 16 October 2019

Weighted Index for Amibroker (AFL)

Weighted Index using AddToComposite and Foreign functions.

 
  
AddToComposite((Close*Volume),  "~GMarketIndx", "I");

AddToComposite(Open*((Close*Volume)/Foreign("~GMarketIndx","I")),"~GMarketIndx", "O");  
AddToComposite(High*((Close*Volume)/Foreign("~GMarketIndx","I")),"~GMarketIndx","H");   
AddToComposite(Low*((Close*Volume)/Foreign("~GMarketIndx","I")),"~GMarketIndx","L");   
AddToComposite(Close*((Close*Volume)/Foreign("~GMarketIndx","I")),"~GMarketIndx", "C"); 
AddToComposite(Volume*((Close*Volume)/Foreign("~GMarketIndx","I")),"~GMarketIndx","V");   
   
Buy = 0;  
 
 
Filter = Close>0;
AddColumn(Close,"Close",1.3);

AddColumn(Close*Volume,"Close*Volume",1.3);
AddColumn(Foreign("~GMarketIndx", "I"),"I",1.3);
AddColumn(Close*((Close*Volume)/Foreign("~GMarketIndx","I")),"CFinal",1.3);

AddColumn(Volume,"Volume",1.3);
AddColumn(Close*Volume,"Close*Volume",1.3);
AddColumn(Foreign("~GMarketIndx", "I"),"I",1.3);
AddColumn(Volume*((Close*Volume)/Foreign("~GMarketIndx","I")),"VFinal",1.3);

2 comments:

  1. sir
    I am trying to create the custom stock market index using the foreign function but due to large no of the foreign function used,amibroker is getting very slow to plot the index. when I reduced the symbols to two or three it is plotting correctly. Can anybody help me with this? Is there any other way to get this. i specifically wanted to multiply individual multiplier to each ticker (for example (free float share) *(closing value)) . How this can be done in addtocomposite function??

    BRITANNIA=117829465*Foreign("BRITANNIA","C");
    TCS=1050667718*Foreign("TCS","C");
    BPCL=802623515.3*Foreign("BPCL","C");
    CIPLA=507950730.6*Foreign("CIPLA","C");
    BAJAJAUTO=130215159*Foreign("BAJAJ-AUTO","C");
    INFY=3662832777*Foreign("INFY","C");
    TotalFreeFloatMarketCap=BRITANNIA+TCS+BPCL+CIPLA+BAJAJAUTO+INFY;

    BRITANNIA1=BRITANNIA/TotalFreeFloatMarketCap;
    TCS1=TCS/TotalFreeFloatMarketCap;
    BPCL1=BPCL/TotalFreeFloatMarketCap;
    CIPLA1=CIPLA/TotalFreeFloatMarketCap;
    BAJAJAUTO1=BAJAJAUTO/TotalFreeFloatMarketCap;
    INFY1=INFY/TotalFreeFloatMarketCap;

    Total=BRITANNIA1+TCS1+BPCL1+CIPLA1+BAJAJAUTO1+INFY1;
    a=TotalFreeFloatMarketCap*1000;
    Plot(a,"",colorRed,styleLine);

    ReplyDelete
    Replies
    1. Hello Prabhas,

      Have you found the solution? Even I'm looking for such similar afl. If you have firured it out, please let me know. It will be really thankful.

      Delete

Thanks