Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Super Simple Indicator keeps on loading om some timeframes

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Super Simple Indicator keeps on loading om some timeframes

    Hi
    I have a super simple indicator I hace placed on 4 charts, but some of the charts it seems that eventhough the data are there the indicator keeps on loading.
    I need to close the window and create a new one then it works again until I change symbol then it crashes again sometimes please see attached image.
    I use Interactive Brokers as the data provider.


    Code:
    public class TheStratScenarios : Indicator
    {
    private string scenario;
    private SolidColorBrush scenarioBrush;
    
    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Description = @"Enter the description for your new custom Indicator here.";
    Name = "TheStratScenarios";
    Calculate = Calculate.OnBarClose;
    IsOverlay = true;
    DisplayInDataBox = true;
    DrawOnPricePanel = true;
    DrawHorizontalGridLines = true;
    DrawVerticalGridLines = true;
    PaintPriceMarkers = true;
    ScaleJustification = NinjaTrader.Gui.Chart.ScaleJustification.Right;
    //Disable this property if your indicator requires custom values that cumulate with each new market data event.
    //See Help Guide for additional information.
    IsSuspendedWhileInactive = true;
    
    //Setting Default Colors
    ColorIB = Brushes.Gold;
    ColorTrend = Brushes.White;
    ColorOB = Brushes.Red;
    }
    else if (State == State.Configure)
    {
    }
    }
    
    protected override void OnBarUpdate()
    {
    if(CurrentBar==0)
    return;
    
    string scenario = GetScenario();
    //Draw.Text(this, CurrentBar.ToString(), scenario, 0, Low[0] - (Low[0]/150),scenarioBrush );
    
    Draw.Text(this,CurrentBar.ToString(),false,scenari o,0, Low[0], -80, scenarioBrush, new SimpleFont("Verdana",12), TextAlignment.Center,Brushes.Transparent,Brushes.T ransparent,0);
    }
    
    private string GetScenario()
    {
    string scenario = "0";
    if(High[0] <= High[1] && Low[0] >= Low[1])
    {//Inside Bar
    scenario = "1";
    scenarioBrush = ColorIB;
    }
    else if (High[0] >= High[1] && Low[0] >= Low[1])
    {
    scenario = "2u";
    scenarioBrush = ColorTrend;
    }
    else if (High[0] <= High[1] && Low[0] <= Low[1])
    {
    scenario = "2d";
    scenarioBrush = ColorTrend;
    }
    else if (High[0] > High[1] && Low[0] < Low[1])
    {
    scenario = "3";
    scenarioBrush = ColorOB;
    }
    
    return scenario;
    }
    [XmlIgnore]
    [ NinjaScriptProperty]
    [Display(ResourceType = typeof(Custom.Resource), Name = "Color IB (1)", GroupName = "NinjaScriptParameters", Order = 0)]
    public SolidColorBrush ColorIB
    { get; set; }
    
    [XmlIgnore]
    [ NinjaScriptProperty]
    [Display(ResourceType = typeof(Custom.Resource), Name = "Color Trend (2)", GroupName = "NinjaScriptParameters", Order = 0)]
    public SolidColorBrush ColorTrend
    { get; set; }
    
    [XmlIgnore]
    [ NinjaScriptProperty]
    [Display(ResourceType = typeof(Custom.Resource), Name = "Color OB (3)", GroupName = "NinjaScriptParameters", Order = 0)]
    public SolidColorBrush ColorOB
    { get; set; }
    }
    Attached Files

    #2
    Hello SuneSorgenfrei,

    Thank you for your post.

    The glaring issue I see in your script is that you're referring to SolidColorBrush but using predefined WPF brushes, and I don't see that you're properly serializing the brushes. I suspect the errors you're receiving likely have to do with that. Here's the revisions I would suggest:

    Code:
    public class TheStratScenarios : Indicator
    {
    private string scenario;
    [B]private Brush scenarioBrush;[/B]
    
    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Description = @"Enter the description for your new custom Indicator here.";
    Name = "TheStratScenarios";
    Calculate = Calculate.OnBarClose;
    IsOverlay = true;
    DisplayInDataBox = true;
    DrawOnPricePanel = true;
    DrawHorizontalGridLines = true;
    DrawVerticalGridLines = true;
    PaintPriceMarkers = true;
    ScaleJustification = NinjaTrader.Gui.Chart.ScaleJustification.Right;
    //Disable this property if your indicator requires custom values that cumulate with each new market data event.
    //See Help Guide for additional information.
    IsSuspendedWhileInactive = true;
    
    //Setting Default Colors
    ColorIB = Brushes.Gold;
    ColorTrend = Brushes.White;
    ColorOB = Brushes.Red;
    }
    else if (State == State.Configure)
    {
    }
    }
    
    protected override void OnBarUpdate()
    {
    if(CurrentBar==0)
    return;
    
    string scenario = GetScenario();
    //Draw.Text(this, CurrentBar.ToString(), scenario, 0, Low[0] - (Low[0]/150),scenarioBrush );
    
    Draw.Text(this,CurrentBar.ToString(),false,scenari o,0, Low[0], -80, scenarioBrush, new SimpleFont("Verdana",12), TextAlignment.Center,Brushes.Transparent,Brushes.T ransparent,0);
    }
    
    private string GetScenario()
    {
    string scenario = "0";
    if(High[0] <= High[1] && Low[0] >= Low[1])
    {//Inside Bar
    scenario = "1";
    scenarioBrush = ColorIB;
    }
    else if (High[0] >= High[1] && Low[0] >= Low[1])
    {
    scenario = "2u";
    scenarioBrush = ColorTrend;
    }
    else if (High[0] <= High[1] && Low[0] <= Low[1])
    {
    scenario = "2d";
    scenarioBrush = ColorTrend;
    }
    else if (High[0] > High[1] && Low[0] < Low[1])
    {
    scenario = "3";
    scenarioBrush = ColorOB;
    }
    
    return scenario;
    }
    #region Properties
    [XmlIgnore]
    [ NinjaScriptProperty]
    [Display(ResourceType = typeof(Custom.Resource), Name = "Color IB (1)", GroupName = "NinjaScriptParameters", Order = 0)]
    [B]public Brush ColorIB[/B]
    { get; set; }
    
    [B][Browsable(false)]
    public string ColorIBSerialize
    {
    get { return Serialize.BrushToString(ColorIB); }
    set { ColorIB = Serialize.StringToBrush(value); }
    }[/B]
    
    [XmlIgnore]
    [ NinjaScriptProperty]
    [Display(ResourceType = typeof(Custom.Resource), Name = "Color Trend (2)", GroupName = "NinjaScriptParameters", Order = 0)]
    [B]public Brush ColorTrend[/B]
    { get; set; }
    
    [B][Browsable(false)]
    public string ColorTrendSerialize
    {
    get { return Serialize.BrushToString(ColorTrend); }
    set { ColorTrend = Serialize.StringToBrush(value); }
    }[/B]
    
    [XmlIgnore]
    [ NinjaScriptProperty]
    [Display(ResourceType = typeof(Custom.Resource), Name = "Color OB (3)", GroupName = "NinjaScriptParameters", Order = 0)]
    [B]public Brush ColorOB[/B]
    { get; set; }
    
    [B][Browsable(false)]
    public string ColorOBSerialize
    {
    get { return Serialize.BrushToString(ColorOB); }
    set { ColorOB = Serialize.StringToBrush(value); }
    }[/B]
    #endregion
    }
    I would suggest reviewing this page of our help guide on working with Brushes:



    Please let us know if we may be of further assistance to you.
    Kate W.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by chbruno, Today, 04:10 PM
    0 responses
    1 view
    0 likes
    Last Post chbruno
    by chbruno
     
    Started by josh18955, 03-25-2023, 11:16 AM
    6 responses
    436 views
    0 likes
    Last Post Delerium  
    Started by FAQtrader, Today, 03:35 PM
    0 responses
    6 views
    0 likes
    Last Post FAQtrader  
    Started by rocketman7, Today, 09:41 AM
    5 responses
    19 views
    0 likes
    Last Post NinjaTrader_Jesse  
    Started by frslvr, 04-11-2024, 07:26 AM
    9 responses
    127 views
    1 like
    Last Post caryc123  
    Working...
    X