龙听期货论坛's Archiver

C
+
+


 微信: QQ:

龙听 发表于 2018-11-27 10:55

Amibroker AFL code by Markos Katsanos — November 2018

[p=30, 2, left]The Amibroker AFL code below is from Markos Katsanos’ November 2018 article “[url=http://technical.traders.com/archive/article.asp?file=\V36\C11\745KATS.pdf]The Stiffness Indicator[/url]”:[/p]
Stiffness IndicatorAmibroker[源码]
[code]
//STIFFNESS INDICATOR
//Copyright Markos Katsanos 2018
Period = Param("Stiffness Period", 60, 2, 1000, 1 );
MAB=Param("Moving Average Period",100,2,1000,1); // MA DAYS
SM=Param("Smooth Coeff.",3,1,20,1); //
STIFFCRIT=Param("STIFFCritical",90,70,100,5);  // STIFFNESS CRITICAL
NSTD=Param("Min SD",.2,0,2,.5); //Number of Standard Deviations
//STIFFNESS
MA2=MA(C,MAB)-NSTD*StDev(C,MAB);
CLMA=C>MA2;
PENS=Sum(CLMA,PERIOD);
STIF=PENS*100/PERIOD; STIFFNESS=EMA(STIF,SM);

Plot(stiffness,"STIFFNESS",colorRed ,styleHistogram );
Plot(STIFFCRIT,"STIFFCritical",colorGreen,styleThick);
[/code]


Stiffness Strategy

[code]
//STIFFNESS STRATEGY
//Copyright Markos Katsanos 2018

PosQty = 500;
SetOption( "MaxOpenPositions", PosQty );
SetPositionSize( 10000, spsValue );  

SetTradeDelays( 1, 1, 1, 1 );
BuyPrice = OPEN;
SellPrice = OPEN;

timeexit =Optimize("exit",4,4,4,1); //MONTHS
MAB=Optimize("MAB",100,50,120,10); // MA DAYS
PERIOD=Optimize(" STIFF PERIOD",60,40,80,10); // STIFFNESS PERIOD
STIFFCRIT=Optimize("STIFFCRIT",90,90,95,5);  // STIFFNESS CRITICAL
STIFFSELL=Optimize("STIFFSELL",50,50,60,10);  // stiffness sell

//STIFFNESS
MA2=MA(C,MAB)-.2*StDev(C,MAB);
CLMA=C>MA2;
PENS=Sum(CLMA,PERIOD);
STIF=PENS*100/PERIOD; STIFFNESS=EMA(STIF,3);

SPY = Foreign("SPY","C");

BUY = EMA(SPY,100)>=Ref(EMA(SPY,100),-2)  AND Cross(STIFFNESS,STIFFCRIT) ;

Sell =Cross(STIFFSELL,STIFFNESS);
ApplyStop( stopTypeNBar, stopModeBars, timeexit*21 ); // time exit
[/code]


Stiffness Exploration

[code]
//STIFFNESS EXPLORATION
//Copyright Markos Katsanos 2018

MAB=100; // MA DAYS
PERIOD=60;// STIFFNESS PERIOD
STIFFCRIT=90;// STIFFNESS CRITICAL

//STIFFNESS
MA2=MA(C,MAB)-.2*StDev(C,MAB);
CLMA=C>MA2;
PENS=Sum(CLMA,PERIOD);
STIF=PENS*100/PERIOD; STIFFNESS=EMA(STIF,3);

SPY = Foreign("SPY","C");
        
FILTER = EMA(SPY,100)>=Ref(EMA(SPY,100),-2) AND Cross(STIFFNESS,STIFFCRIT) ;

AddColumn(C,"Price",1.2);               
AddColumn(Volume,"Volume",1.0);
AddColumn(MA(Volume,2)/MA(Volume,50),"V/Vave",1.2);
AddColumn(RSI(6),"RSI",1);
AddColumn(STIFFNESS,"STIFFNESS",1.2);
AddColumn(C+8*ATR(50),"PROFIT TARGET",1.2);
[/code]

获嘉小马哥 发表于 2019-3-27 12:03

感谢分享

页: [1]