10
crossover events
19 Mar 2014, 23:35
Hello,
I submitted a question a few days ago and I was impressed with how quick a response I received. I am not a programmer so this is likely easy for everyone but I need the help. I am looking to very simply perform a market buy or sell when a fast weighted moving average crosses over a slower weighted moving average. I looked through sample cbots but didn't find anything that really fit this very simple trading technique.
Any help is appreciated. Below is theoretically what I am trying to do but can't figure out the syntax
if ( fastWMA > slow WMA)
{
Buy;
}
if ( fastWMA < slowWMA) { Sell; }
Thank-you.

Old Account
21 Mar 2014, 20:23
using System; using System.Linq; using cAlgo.API; using cAlgo.API.Indicators; using cAlgo.API.Internals; using cAlgo.Indicators; namespace cAlgo { [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)] public class NewcBot : Robot { [Parameter("Fast Periods", DefaultValue = 10)] public int F_Periods { get; set; } [Parameter("Slow Periods", DefaultValue = 20)] public int S_Periods { get; set; } [Parameter("Volume", DefaultValue = 1000)] public int Volume { get; set; } public WeightedMovingAverage F_WMA; public WeightedMovingAverage S_WMA; public bool TradeS; public bool TradeB; protected override void OnStart() { F_WMA = Indicators.WeightedMovingAverage(MarketSeries.Close, F_Periods); S_WMA = Indicators.WeightedMovingAverage(MarketSeries.Close, S_Periods); } protected override void OnTick() { bool isBuyPositionOpen = Positions.Count != 0 && LastResult.Position.TradeType == TradeType.Buy; bool isSellPositionOpen = Positions.Count != 0 && LastResult.Position.TradeType == TradeType.Sell; if (S_WMA.Result.LastValue > F_WMA.Result.LastValue && !isSellPositionOpen && TradeS) { ExecuteMarketOrder(TradeType.Sell, Symbol, Volume, "", 20, 20); TradeS = false; } if (S_WMA.Result.LastValue < F_WMA.Result.LastValue && !isBuyPositionOpen && TradeB) { ExecuteMarketOrder(TradeType.Buy, Symbol, Volume, "", 20, 20); TradeB = false; } } protected override void OnBar() { TradeS = true; TradeB = true; } } }@Old Account