NexusFi: Find Your Edge


Home Menu

 





Help for a simple entry strategy


Discussion in MultiCharts

Updated
    1. trending_up 1,951 views
    2. thumb_up 0 thanks given
    3. group 1 followers
    1. forum 0 posts
    2. attach_file 0 attachments




 
Search this Thread

Help for a simple entry strategy

  #1 (permalink)
r41866
Cypress Texas/USA
 
Posts: 10 since Mar 2021
Thanks Given: 0
Thanks Received: 1

I want to write a simple entry strategy for Multicharts.Net. Just calculate the current bar's height and determine whether it is a bullish bar. If the bar is bullish and closed above 60% of the height, place a stop order one tick above the high of the current bar. The risk per futures contract will be the height of the current bar plus 2 ticks. The input value is the total risk tolerated per trade in dollar value and the risk tolerated per futures contract in dollar value. If the risk is larger than the risk tolerated per futures contact, there is no trade. If the risk calculated according to the bar height plus two ticks is less than the risk tolerance, the number of contracts for the order is the total risk tolerance divided by the risk per contract and rounded down.

Below is the code I wrote. Yet after I applied the code to ES futures symbol, the order was never triggered. I used Output.WriteLine to debug and I found something weird. I use CurrentPosition.Value to know the current open position and the order is submitted only if there is no open position. Yet I found CurrentPosition.Value is 4 most of the times even if there is nothing open. The CurrentPosition.Value is 0 only when the time is 8:33 pm US central standard time on Jan 27, 2021. The chart I use is a 2000 tick chart. If I use StrategyInfo.MarketPosition to detect the market open position, I get the value exactly the same as CurrentPosition.Value. Please advise what's gone wrong.

using System;
using System.Drawing;
using System.Linq;
using PowerLanguage.Function;
using ATCenterProxy.interop;


namespace PowerLanguage.Strategy
{
[IOGMode(IOGMode.Disabled)]
public class MackBuyStop_Open : SignalObject
{
// Create the inputs
[Input]
public double Max_Risk { get; set; }

[Input]
public double PerContract_Risk { get; set; }

public MackBuyStop_Open(object _ctx) : base(_ctx)
{
// Give the inputs a default value
Max_Risk = 950;
PerContract_Risk = 300;

}

private IOrderPriced enterLong;
private double TickValue, PointValue, BarRisk;


protected override void Create()
{
// Create the orders
enterLong = OrderCreator.Stop(new
SOrderParameters(Contracts.UserSpecified, EOrderAction.Buy));



}

protected override void StartCalc()
{
TickValue = Bars.Info.MinMove / Bars.Info.PriceScale ;
PointValue = Bars.Info.BigPointValue ;
Output.Clear();

}

protected override void CalcBar()
{

BarRisk = ( Bars.High[0] - Bars.Low[0] + 2 * TickValue ) * PointValue ;


if ((CurrentPosition.Value == 0) &&
( Bars.Close[0] - Bars.Open[0] > 0 ) &&
( (Bars.Close[0] - Bars.Low[0] ) / (Bars.High[0] - Bars.Low[0]) >= 0.6 ) &&
( BarRisk <= PerContract_Risk )) //((double)(Bars.High - Bars.Low) + 2 * TickValue)
{
Output.WriteLine(Bars.Time[0].ToString("d-M HH:mm:ss")+" Market Position = {0}\n", CurrentPosition.Value);
if (BarRisk <= PerContract_Risk)
{
enterLong.Send(Bars.High[0] + TickValue, (int)(Max_Risk/BarRisk));

}

}


}
}
}

Reply With Quote




Last Updated on March 14, 2021


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top
no new posts