See your orders on the graph

Created at 20 Feb 2016, 11:03
How’s your experience with the cTrader Platform?
Your feedback is crucial to cTrader's development. Please take a few seconds to share your opinion and help us improve your trading experience. Thanks!
gainer's avatar

gainer

Joined 24.01.2016

See your orders on the graph
20 Feb 2016, 11:03


I developed this snippet of code to have always under my eyes the last orders, since midnight OR AFTER, buy you can easily adapt the code to your exigences

I hope it may be usefull...

 

private DateTime sincePips = new DateTime(2016, 2, 19, 13, 0, 0);

private Colors colorBuy = Colors.Lime;
private Colors colorSell = Colors.Red;
private Colors colorNone = Colors.Yellow;

protected override void OnStart()
{
    double totPips = 0.0;
    string history = string.Empty;
    DateTime sinceTime = (DateTime.Now.Date > sincePips ? DateTime.Now : sincePips);
    Colors colorPips = Colors.Black;

    for (int i = History.Count - 1; i >= 0; i--)
    {
        if (History[i].ClosingTime < sinceTime)
        {
            break;
        }
        totPips += History[i].Pips;
        history += History[i].SymbolCode + " " + History[i].Pips + " " + History[i].ClosingTime + "\r\n";

        if (totPips > 0)
        {
            colorPips = colorBuy;
        }
        else if (totPips < 0)
        {
            colorPips = colorSell;
        }
        else
        {
            colorPips = colorNone;
        }
    }

    history = (totPips > 0 ? "Tot pips GAIN " : "Take pips LOSS ") + totPips.ToString("N1") + "\r\n-----\r\n" + history;
    ChartObjects.DrawText("Pips", history, StaticPosition.TopRight, colorPips);
}

 


@gainer
Replies

gainer
20 Feb 2016, 11:11

...ops... excuse me, an error, because I extracted the snippet from one of my cBots

the setting of colors must be outside of the loop

suggestions:

  • you may put the "sincePips" as a parameter
  • you can put the code as a method and call it periodically from OnTick or with a timer
private DateTime sincePips = new DateTime(2016, 2, 19, 13, 0, 0);

private Colors colorBuy = Colors.Lime;
private Colors colorSell = Colors.Red;
private Colors colorNone = Colors.Yellow;

protected override void OnStart()
{
    double totPips = 0.0;
    string history = string.Empty;
    DateTime sinceTime = (DateTime.Now.Date > sincePips ? DateTime.Now : sincePips);
    Colors colorPips = Colors.Black;

    for (int i = History.Count - 1; i >= 0; i--)
    {
        if (History[i].ClosingTime < sinceTime)
        {
            break;
        }

        totPips += History[i].Pips;
        history += History[i].SymbolCode + " " + History[i].Pips + " " + History[i].ClosingTime + "\r\n";
    }

    if (totPips > 0)
    {
        colorPips = colorBuy;
    }
    else if (totPips < 0)
    {
        colorPips = colorSell;
    }
    else
    {
        colorPips = colorNone;
    }

    history = (totPips > 0 ? "Tot pips GAIN " : "Take pips LOSS ") + totPips.ToString("N1") + "\r\n-----\r\n" + history;
    ChartObjects.DrawText("Pips", history, StaticPosition.TopRight, colorPips);
}

 


@gainer