I was browsing around and found this link:
It is a video tutorial from bigmike. Very good tutorial.
His stop losses, breakeven points and targets are based on Points. I want to use percentages.
I edited the code, but It seems It's not working properly. Please help as I am not a expert programmer and all of this is very new to me!
/// <summary>
/// Big Mike - 1/26/10 - http://www.bigmiketrading.com/beginn...-strategy.html
/// </summary>
[Description("Make me millions Jan 27 2010")]
public class CrossoverTargets : Strategy
{
//#region Variables
// targets based on percentage, when I change the targets to 0.01, I get an error b/c of ''int"
private int target1 = 12;
private int target2 = 10;
private int target3 = 24;
//stop loss based on points/ticks. I want to make the stoploss 1 penny, so 0.01.
private int stop = 12;
private bool be2 = true;
private bool be3 = true;
//#endregion
/// <summary>
/// This method is used to configure the strategy and is called once before any strategy method is called.
/// </summary>
protected override void Initialize()
{
CalculateOnBarClose = true;
EntryHandling = EntryHandling.UniqueEntries;
}
private void GoLong()
{
// stoplosses based on entry price minus the stoploss points/ticks that I've assigned above.
SetStopLoss("target1", CalculationMode.Price, Position.AvgPrice - (Stop*TickSize), false);
SetStopLoss("target2", CalculationMode.Price, Position.AvgPrice - (Stop*TickSize), false);
SetStopLoss("target3", CalculationMode.Price,Position.AvgPrice - (Stop*TickSize), false);
//profit targets based on percentage. So if price moves up 0.01% I want that to be my first target.. and so on. This is why I added a 1+ next to all the targets. In match.. 1.001*Entryprice should give me the target.
SetProfitTarget("target1", CalculationMode.Price, Position.AvgPrice * ((1+Target1)*TickSize));
SetProfitTarget("target2", CalculationMode.Price, Position.AvgPrice * (((1+Target1)+(1+Target2))*TickSize));
SetProfitTarget("target3", CalculationMode.Price, Position.AvgPrice * (((1+Target1)+(1+Target2)+(1+Target3))*TickSize));
EnterLong("target1");
EnterLong("target2");
EnterLong("target3");
}
private void GoShort()
{
SetStopLoss("target1", CalculationMode.Price, Position.AvgPrice + (Stop*TickSize), false);
SetStopLoss("target2", CalculationMode.Price, Position.AvgPrice + (Stop*TickSize), false);
SetStopLoss("target3", CalculationMode.PricePosition.AvgPrice + (Stop*TickSize), false);
SetProfitTarget("target1", CalculationMode.Price, Position.AvgPrice * ((1-Target1)*TickSize));
SetProfitTarget("target2", CalculationMode.Price, Position.AvgPrice * (((1-Target1)+(1-Target2))*TickSize));
SetProfitTarget("target3", CalculationMode.Price, Position.AvgPrice * (((1-Target1)+(1-Target2)+(1-Target3))*TickSize));
EnterShort("target1");
EnterShort("target2");
EnterShort("target3");
}
private void ManageOrders()
{
if (Position.MarketPosition == MarketPosition.Long)
{
if (BE2 && High[0] > Position.AvgPrice + (Target1*TickSize))
SetStopLoss("target2", CalculationMode.Price, Position.AvgPrice, false);
if (BE3 && High[0] > Position.AvgPrice + ((Target1+Target2)*TickSize))
SetStopLoss("target3", CalculationMode.Price, Position.AvgPrice, false);
}
if (Position.MarketPosition == MarketPosition.Short)
{
if (BE2 && Low[0] < Position.AvgPrice - (Target1*TickSize))
SetStopLoss("target2", CalculationMode.Price, Position.AvgPrice, false);
if (BE3 && Low[0] < Position.AvgPrice - ((Target1+Target2)*TickSize))
SetStopLoss("target3", CalculationMode.Price, Position.AvgPrice, false);
}
}
/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{
EntryHandling = EntryHandling.UniqueEntries;
ManageOrders();
// Condition set 1
if (CrossAbove(CCI(14), 250, 1))
EnterShort();
// Condition set 2
if (CrossBelow(CCI(14), 250, 1))
EnterLong();
}
//#region Properties
[Description("")]
[Category("Parameters")]
public int Target1
{
get { return target1; }
set { target1 = Math.Max(1, value); }
}
[Description("")]
[Category("Parameters")]
public int Target2
{
get { return target2; }
set { target2 = Math.Max(1, value); }
}
[Description("")]
[Category("Parameters")]
public int Target3
{
get { return target3; }
set { target3 = Math.Max(1, value); }
}
[Description("")]
[Category("Parameters")]
public int Stop
{
get { return stop; }
set { stop = Math.Max(1, value); }
}
[Description("")]
[Category("Parameters")]
public bool BE2
{
get { return be2; }
set { be2 = value; }
}
[Description("")]
[Category("Parameters")]
public bool BE3
{
get { return be3; }
set { be3 = value; }
}
//#endregion
}
}
Thank you for all the help!
Comment