Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Text;
- using WealthLab;
- using WealthLab.Indicators;
- using System.Drawing;
- namespace WealthLabCompile
- {
- class ChannelBreakoutVT : WealthScript
- {
- //Create parameters
- private StrategyParameter longChannelPer;
- private StrategyParameter shortChannelPer;
- public ChannelBreakoutVT()
- {
- longChannelPer = CreateParameter("Long Channel", 280, 20, 500, 10);
- shortChannelPer = CreateParameter("Short Channel", 210, 10, 250, 5);
- }
- protected override void Execute()
- {
- //Obtain periods from parameters
- int longPer = longChannelPer.ValueInt;
- int shortPer = shortChannelPer.ValueInt;
- bool ifLongDay = false;
- DataSeries H55 = Highest.Series(High, longPer);
- DataSeries L55 = Lowest.Series(Low, longPer);
- DataSeries H21 = Highest.Series(High, shortPer);
- DataSeries L21 = Lowest.Series(Low, shortPer);
- // shift the plotted series to the right one bar to visualize the crossings
- PlotSeries(PricePane, H55 >> 1, Color.Green, LineStyle.Solid, 1);
- PlotSeries(PricePane, L21 >> 1, Color.Red, LineStyle.Dotted, 1);
- PlotSeries(PricePane, H21 >> 1, Color.Blue, LineStyle.Dotted, 1);
- PlotSeries(PricePane, L55 >> 1, Color.Fuchsia, LineStyle.Solid, 1);
- for (int bar = longPer; bar < Bars.Count; bar++)
- {
- if (Bars.IntradayBarNumber(bar) == 0)
- {
- ifLongDay = Close[bar] > Open[bar];
- }
- if (IsLastPositionActive)
- {
- Position Pos = LastPosition;
- if (Pos.PositionType == PositionType.Long)
- SellAtStop(bar + 1, LastPosition, L21[bar]);
- else
- CoverAtStop(bar + 1, LastPosition, H21[bar]);
- }
- else
- {
- RiskStopLevel = L21[bar];
- if (BuyAtStop(bar + 1, H55[bar]) == null)
- {
- RiskStopLevel = H21[bar];
- ShortAtStop(bar + 1, L55[bar]);
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement