Hello,
Has anyone come up with a way to get the current price of an instrument. I know you can reference the open, close, high, low price but I need the price at that current moment, between bars. I don't know of a direct way to do this, but it may be possible since referencing GetOpenPL() returns second by second changes to the current open P&L.
For example, the below is a handy little label I have at the top of my charts that give me my current P&L and it changes second by second, so it has to be getting the price. I have created a strategy that uses a stoploss based on points, but the problem I have is if the "low" is below the number of points I specified when a long trade is triggered, it's immediately throwing up a close signal.
Now, you may be wondering, "Why does this guy want to do this...." and you'd be right to wonder. I've been using a macro program to read label colors from my strategy to automatically submit buy, sell, flatten orders. So far, so good except I want to stop out based on pts (eg: 5pt stop on MES) instead of the low of the last bar, etc.
Regards, Kevin
Has anyone come up with a way to get the current price of an instrument. I know you can reference the open, close, high, low price but I need the price at that current moment, between bars. I don't know of a direct way to do this, but it may be possible since referencing GetOpenPL() returns second by second changes to the current open P&L.
For example, the below is a handy little label I have at the top of my charts that give me my current P&L and it changes second by second, so it has to be getting the price. I have created a strategy that uses a stoploss based on points, but the problem I have is if the "low" is below the number of points I specified when a long trade is triggered, it's immediately throwing up a close signal.
Now, you may be wondering, "Why does this guy want to do this...." and you'd be right to wonder. I've been using a macro program to read label colors from my strategy to automatically submit buy, sell, flatten orders. So far, so good except I want to stop out based on pts (eg: 5pt stop on MES) instead of the low of the last bar, etc.
Code:
# Next line is a handy reference
#Colors for GetColor 0(violet), 1(baby blue), 2(pink), 3(gray), 4(yelllow), 5(red), 6(green), 7(dark gray), 8(pale yellow), 9(white)
declare hide_on_daily;
def price = close;
def averagePrice=GetAveragePrice();
def shareSize = GetQuantity();
def cost = averagePrice * shareSize;
def accountValue = (shareSize * close) - (shareSize * averagePrice);
plot AverageTradePrice=if(averagePrice > 0, averagePrice, double.NaN);
AverageTradePrice.SetDefaultColor(COLOR.GREEN);
AverageTradePrice.SetStyle(CURVE.SHORT_DASH);
# Plot the daily MA's
plot MA20 = MovingAverage(AverageType.EXPONENTIAL, close(period = aggregationPeriod.DAY), 20);
MA20.setdefaultColor(color.red);
MA20.setStyle(Curve.POINTS);
plot MA50 = MovingAverage(AverageType.SIMPLE, close(period = aggregationPeriod.DAY), 50);
MA50.setdefaultColor(color.green);
MA50.setStyle(Curve.POINTS);
plot MA100 = MovingAverage(AverageType.SIMPLE, close(period = aggregationPeriod.DAY), 100);
MA100.setdefaultColor(color.violet);
MA100.setStyle(Curve.POINTS);
plot MA200 = MovingAverage(AverageType.SIMPLE, close(period = aggregationPeriod.DAY), 200);
MA200.setdefaultColor(color.yellow);
MA200.setStyle(Curve.POINTS);
# End Daily MA's
input fastLength = 09;
input slowLength = 20;
input verySlowLength = 50;
input superSlowLength = 200;
input averageType = AverageType.EXPONENTIAL;
plot FastMA = MovingAverage(averageType, price, fastLength);
plot SlowMA = MovingAverage(averageType, price, slowLength);
plot VerySlowMA = MovingAverage(averageType, price, verySlowLength);
plot SuperSlowMA = MovingAverage(averageType, price, SuperSlowLength);
FastMA.SetDefaultColor(GetColor(1));
SlowMA.SetDefaultColor(GetColor(2));
VerySlowMA.SetDefaultColor(GetColor(6));
SuperSlowMA.SetDefaultColor(GetColor(4));
AddLabel(if (GetOpenPL() <> 0,1,0),
"Avg: " + round(averagePrice) +
", Qty: " + shareSize +
", PnL: $" + GetOpenPL() +
", Gain: " + round(GetOpenPL() / AbsValue(cost) * 100) + "%" +
", Cost: $" + cost +
", Used: " + AsPercent(cost / GetNetLiq())
, if accountValue > 0
then Color.GREEN
else if accountValue < 0
then Color.PINK
else Color.GRAY);
Regards, Kevin