Search code examples
debuggingpine-scriptalgorithmic-trading

How to see what value is being calculated pine Editor


I have the following script running with the intention of closing a trade after it has been open for a period of 4 days since the trade was taken.

TimeDiff = time - time[1]
MinutesPerBar = TimeDiff / 60000  
//calcuates how long one bar is in minutes

BarsSinceSwingLongCondition = barssince(SwingLongCondition)  
// Calculates how many bars have passed since open of trade
CurrentSwingTradeDuration = BarsSinceSwingLongCondition * MinutesPerBar 
//calculates the duration that the trade has been opened for (minutes*number of bars) 
MaximumSwingTradeDuration = 4*1440 
// Sets maximum trade duration.  Set at 4 Days in minutes

SwingLongCloseLogic3 = CurrentSwingTradeDuration > MaximumSwingTradeDuration 
// Closes trade when trade duration exceeds maximum duration set (4days)

The close logic however isn't executing when I run the strategy as i have trades open for longer than the maximum duration.

Is there any way to see what value each element of the formula is calculating so that I can see where the error is (i suspect it could be the time element). Or can anyone see where I am going wrong in the code?


Solution

  • The fastest way to achieve that is using the plotchar function, which would show the values in the data-window on mouse-over on each bar. The user manual contains several other techniques available for debugging.