Created
May 30, 2025 17:43
-
-
Save 18182324/756320db1895b954a2af0d4400a988f4 to your computer and use it in GitHub Desktop.
Easy Language TradeStation Indicator Profit Expectancy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Inputs: | |
Length(14); // Optimizable lookback period | |
Vars: | |
UpCount(0), | |
DownCount(0), | |
UpSum(0), | |
DownSum(0), | |
i(0), | |
PriceChange(0), | |
RS(0), | |
RSI(0), | |
PPI(0), | |
PayoffOdds(0), | |
Expectancy(0); | |
// Reset counters | |
UpCount = 0; | |
DownCount = 0; | |
UpSum = 0; | |
DownSum = 0; | |
// Loop through the last 'Length' bars | |
For i = 1 to Length begin | |
PriceChange = Close[i-1] - Close[i]; | |
If PriceChange > 0 then begin | |
UpCount = UpCount + 1; | |
UpSum = UpSum + PriceChange; | |
end | |
else if PriceChange < 0 then begin | |
DownCount = DownCount + 1; | |
DownSum = DownSum + AbsValue(PriceChange); | |
end; | |
end; | |
// Calculate PPI | |
If (UpCount + DownCount) > 0 then | |
PPI = 100 * (UpCount / (UpCount + DownCount)) | |
Else | |
PPI = 50; // Neutral if no movement | |
// Calculate RSI using Wilder’s formula | |
If DownSum <> 0 then | |
RS = UpSum / DownSum | |
Else | |
RS = 0; | |
If DownSum = 0 and UpSum > 0 then | |
RSI = 100 | |
Else if DownSum = 0 and UpSum = 0 then | |
RSI = 50 | |
Else | |
RSI = 100 - (100 / (1 + RS)); | |
// Calculate Payoff Odds: RS = UP/DN | |
// Adjusted with bar count imbalance from PPI | |
If PPI <> 0 and PPI <> 100 then | |
PayoffOdds = (RSI * (100 - PPI)) / ((100 - RSI) * PPI) | |
Else | |
PayoffOdds = 1; | |
// Calculate Expectancy: E = (b - 1) * q | |
Expectancy = ((RSI / (100 - RSI)) - 1) * (1 - (PPI / 100)); | |
// Plotting | |
Plot1(PPI, "PPI"); | |
Plot2(RSI, "RSI"); | |
Plot3(PayoffOdds, "PayoffOdds"); | |
Plot4(Expectancy, "Expectancy"); | |
// Color coding for signals (optional) | |
If Expectancy > 0 then | |
SetPlotColor(4, Green) | |
Else | |
SetPlotColor(4, Red); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment