2013년 6월 22일 토요일

Not That Way Bullish

input : Strength(2),Fast(3),Slow(10),Signal(16),Alignment(2),Length(20),
  PercentToEnter(50),PcntSetupBars(50),PercentToexit(50);
var : PriceXValue(0),PriceXbarsAgo(0),PriceZvalue(0),PriceZbarsAgo(0),
 IndicatorXValue(0),IndicatorXBarsAgo(0),IndicatorZValue(0),IndicatorZbarsAgo(0),
 PricePivot(0),IndicatorPivot(0),Indicator(0),AlignedByPrice(False),
 AlignedByIndicator(False),Divergence(False),CheckCrossover(False),SignalLine(0),
 EntryHolder(0),BarsToEnter(0),EntryStop(0),EntrySetup(False),Setupcounter(0),
 Exitholder(0),ExitPercentage(0),MP(0),Exitstop(0),IntervalPeak(0),ProfitTarget(0);

PricePivot = SwingLow(1,L,Strength,Strength,Strength*2+1);
indicator = MACD(Fast,Slow);
SignalLine = Ema(Indicator,Signal);
IndicatorPivot = SwingLow(1,indicator,Strength,Strength,Strength*2+1);

if PricePivot != -1 Then
 if MRO(IndicatorPivot != -1,Alignment,1) != -1 Then
  AlignedByPrice = True;

if AlignedByPrice Then{
 AlignedByPrice = False;
 PriceXValue = PriceZValue;
 PriceXBarsAgo = PriceZbarsAgo;
 IndicatorXValue = IndicatorZValue;
 IndicatorXBarsAgo = indicatorZbarsAgo;
 PriceZValue = PricePivot;
 PriceZBarsAgo = Strength;
 IndicatorZbarSAgo = Mro(IndicatorPivot != -1,Alignment,1)+Strength;
 IndicatorZvalue = indicator[indicatorZbarsAgo];
 Divergence = PriceXvalue > PriceZvalue and IndicatorXvalue < IndicatorZvalue and PriceXValue != 0;
}

if PricePivot == -1 and IndicatorPivot != -1 Then
 if MRO(PricePivot != -1, Alignment,1) != -1 Then
  AlignedByIndicator = True;

if AlignedByIndicator Then{
 AlignedByIndicator = False;
 IndicatorXValue = IndicatorZValue;
 IndicatorXBarsAgo = IndicatorZbarsAgo;
 PriceXValue = PriceZValue;
 PriceXBarsAgo = PriceZbarsAgo;
 IndicatorZValue = IndicatorPivot;
 IndicatorZBarsAgo = Strength;
 PriceZbarSAgo = Mro(PricePivot != -1,Alignment,1)+Strength;
 PriceZvalue = H[indicatorZbarsAgo];
 Divergence = PriceXvalue > PriceZvalue and IndicatorXvalue < IndicatorZvalue and PriceXValue != 0;
}

If Divergence then{
    Divergence = False;
 CheckCrossOver = True;
 EntryHolder = (PriceXvalue-PriceZvalue)*PercentToEnter/100;
 BarsToEnter = (PriceXbarsAgo-PriceZbarsAgo)*PcntSetupBars/100;
 ExitHolder = (PriceXvalue-PriceZvalue)*PercentToExit/100;
 IntervalPeak = Highest(H,PriceXbarsAgo-PriceZbarsAgo)[PriceZBarsAgo]-(PriceZvalue+PriceXvalue)/2;   
}

PriceXbarsAgo = Iff(PriceXbarsAgo < Length,PriceXbarsAgo+1,0);
PriceZbarsAgo = Iff(PriceZbarsAgo > PriceXbarsAgo,PriceZbarsAgo+1,0);
if PriceZbarsAgo == 0 Then
 PriceZvalue = 0;
IndicatorXbarsAgo = iff(indicatorXbarsAgo < Length,IndicatorXbarsAgo+1,0);
IndicatorZbarsAgo = iff(indicatorZbarsAgo < Length,IndicatorZbarsAgo+1,0);

if CheckCrossover Then{
 if CrossUp(indicator,SignalLine) then{
  CheckCrossover = False;
  EntryStop = C-entryHolder;
  EntrySetup = True;
  Setupcounter = BarsToEnter;
  ExitPercentage = ExitHolder;
   }
}

if EntrySetup then{
    setupcounter = Setupcounter-1;
    if setupcounter == 0 Then
     Entrysetup = False;
    if MarketPosition() != 1 Then
     buy("매수",atstop,EntryStop);
}

MP = MarketPosition();

if MP == 1 then{
    EntrySetup = False;
    if MP != MP[1] then{
  ExitStop = EntryPrice()+ExitPercentage;
  ProfitTarget = EntryPrice()-IntervalPeak;
 }
 else if CrossUp(c,entryPrice-ExitPercentage) Then
  #ExitCommission()과 EntryCommission())을 포인트로 설정하고 지정해야함
  exitstop = EntryPrice+((ExitCommission()+EntryCommission())/Bigpointvalue);
 ExitShort("Stop",AtStop,exitStop);
 ExitShort("Profit",atlimit,ProfitTarget);
}

댓글 없음:

댓글 쓰기