Advertisement
Guest User

Untitled

a guest
Oct 21st, 2012
1,228
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.97 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using WealthLab;
  5. using WealthLab.Indicators;
  6. using System.Drawing;
  7.  
  8. namespace WealthLabCompile
  9. {
  10.   class ChannelBreakoutVT : WealthScript
  11.   {
  12.     //Create parameters
  13.     private StrategyParameter longChannelPer;
  14.     private StrategyParameter shortChannelPer;
  15.  
  16.     public ChannelBreakoutVT()
  17.     {
  18.       longChannelPer = CreateParameter("Long Channel", 280, 20, 500, 10);
  19.       shortChannelPer = CreateParameter("Short Channel", 210, 10, 250, 5);
  20.     }
  21.  
  22.     protected override void Execute()
  23.     {
  24.       //Obtain periods from parameters
  25.       int longPer = longChannelPer.ValueInt;
  26.       int shortPer = shortChannelPer.ValueInt;
  27.       bool ifLongDay = false;
  28.  
  29.       DataSeries H55 = Highest.Series(High, longPer);
  30.       DataSeries L55 = Lowest.Series(Low, longPer);
  31.       DataSeries H21 = Highest.Series(High, shortPer);
  32.       DataSeries L21 = Lowest.Series(Low, shortPer);
  33.  
  34.         // shift the plotted series to the right one bar to visualize the crossings
  35.       PlotSeries(PricePane, H55 >> 1, Color.Green, LineStyle.Solid, 1);
  36.       PlotSeries(PricePane, L21 >> 1, Color.Red, LineStyle.Dotted, 1);
  37.       PlotSeries(PricePane, H21 >> 1, Color.Blue, LineStyle.Dotted, 1);
  38.       PlotSeries(PricePane, L55 >> 1, Color.Fuchsia, LineStyle.Solid, 1);
  39.  
  40.       for (int bar = longPer; bar < Bars.Count; bar++)
  41.       {
  42.         if (Bars.IntradayBarNumber(bar) == 0)
  43.         {
  44.             ifLongDay = Close[bar] > Open[bar];
  45.         }              
  46.                
  47.         if (IsLastPositionActive)
  48.         {
  49.           Position Pos = LastPosition;
  50.           if (Pos.PositionType == PositionType.Long)
  51.             SellAtStop(bar + 1, LastPosition, L21[bar]);
  52.           else
  53.             CoverAtStop(bar + 1, LastPosition, H21[bar]);
  54.         }
  55.         else
  56.        {
  57.             RiskStopLevel = L21[bar];
  58.             if (BuyAtStop(bar + 1, H55[bar]) == null)
  59.             {
  60.                         RiskStopLevel = H21[bar];
  61.                         ShortAtStop(bar + 1, L55[bar]);
  62.             }
  63.           }
  64.         }
  65.       }
  66.     }
  67.   }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement