MAMA with Buy Sell Signals and P&L - ThinkOrSwim Programming | futures io social day trading
futures io futures trading


MAMA with Buy Sell Signals and P&L
Updated: Views / Replies:5,459 / 2
Created: by ebtrader Attachments:0

Welcome to futures io.

(If you already have an account, login at the top of the page)

futures io is the largest futures trading community on the planet, with over 90,000 members. At futures io, our goal has always been and always will be to create a friendly, positive, forward-thinking community where members can openly share and discuss everything the world of trading has to offer. The community is one of the friendliest you will find on any subject, with members going out of their way to help others. Some of the primary differences between futures io and other trading sites revolve around the standards of our community. Those standards include a code of conduct for our members, as well as extremely high standards that govern which partners we do business with, and which products or services we recommend to our members.

At futures io, our focus is on quality education. No hype, gimmicks, or secret sauce. The truth is: trading is hard. To succeed, you need to surround yourself with the right support system, educational content, and trading mentors Ė all of which you can find on futures io, utilizing our social trading environment.

With futures io, you can find honest trading reviews on brokers, trading rooms, indicator packages, trading strategies, and much more. Our trading review process is highly moderated to ensure that only genuine users are allowed, so you donít need to worry about fake reviews.

We are fundamentally different than most other trading sites:
  • We are here to help. Just let us know what you need.
  • We work extremely hard to keep things positive in our community.
  • We do not tolerate rude behavior, trolling, or vendors advertising in posts.
  • We firmly believe in and encourage sharing. The holy grail is within you, we can help you find it.
  • We expect our members to participate and become a part of the community. Help yourself by helping others.

You'll need to register in order to view the content of the threads and start contributing to our community.  It's free and simple.

-- Big Mike, Site Administrator

Reply
 
Thread Tools Search this Thread
 

MAMA with Buy Sell Signals and P&L

  #1 (permalink)
Trading Apprentice
east brunswick
 
Futures Experience: Master
Platform: TOS, Tradestation
Favorite Futures: CL, ES, GC, 6E, 6A, 6J, 6B
 
Posts: 3 since Dec 2010
Thanks: 0 given, 3 received

MAMA with Buy Sell Signals and P&L

I put some Buy/Sell Signals in Ehler's MAMA and I wanted to integrate VicEquity's P&L to keep a running total of P&L from this strategy - any ideas on how to integrate them? I have pasted the code for both below:

#################################
# Study: VicEquity

# Date: Dec 1 2010
# Purpose: to display current P/L equity position on chart window.
#################################

# User Inputs:
input TransactionType = {default Long, "Short"}; # Define if we are going long or short
input StartPrice = 1190; # price at which we initated the position
input ContractSize = 1; # number of contracts bought or sold
input Equity = {default "/ES", "/6A", "/TF", "/YM", "/NQ", "/6E", "/GC", "/CL"}; # drop down list of several symbols

def CurPrice = close; # we'll measure against the current close price (could be variable pointing to High or Low or H+L/2 etc...)

# different futures have different multipliers... let's hard code it for one time...great if it can be pulled from some library/repository
def FuturesMultiplier;
def tickSize;

switch (Equity) {
case "/ES": # S & P E-mini
FuturesMultiplier = 12.5;
tickSize = .25;

case "/6A": # Aussie
FuturesMultiplier = 125000;
tickSize = 1; # I have no idea, someone else can look this up
default:
FuturesMultiplier = 1;
tickSize = 1;
}

def ProfitLoss;
switch (TransactionType) {
case "Long":
ProfitLoss = (CurPrice - StartPrice)/tickSize * ContractSize * FuturesMultiplier;
case "Short":
ProfitLoss = (StartPrice - CurPrice)/tickSize * ContractSize * FuturesMultiplier;

}

# Label on top left corner
# paste a label on upper chart showing the P/L for the contract..
AddChartLabel(yes,
concat(getSymbolPart(), concat(TransactionType, concat(" : $", ProfitLoss))),
if ProfitLoss >= 0 then color.green else color.red );


# Here is Ehler's MAMA:
# hint: <b>Ehler's Mesa Adaptive Moving Average</b> using Ray's clean version
# of the homodyne discriminator.
#

# MIT License
# Copyright (c) <2010> <Radford Juang>
#
#Permission is hereby granted, free of charge, to any person obtaining a copy
#of this software and associated documentation files (the "Software"), to deal
#in the Software without restriction, including without limitation the rights
#to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
#copies of the Software, and to permit persons to whom the Software is
#furnished to do so, subject to the following conditions:
#
#The above copyright notice and this permission notice shall be included in
#all copies or substantial portions of the Software.
#
#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
#IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
#FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
#AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
#LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
#OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
#THE SOFTWARE.
#

script WMA_Smooth {
input price = hl2;
plot smooth = (4 * price
+ 3 * price[1]
+ 2 * price[2]
+ price[3]) / 10;
}

script Phase_Accumulation {
# This is Ehler's Phase Accumulation code. It has a full cycle delay.
# However, it computes the correction factor to a very high degree.
#
input price = hl2;

rec Smooth;
rec Detrender;
rec Period;
rec Q1;
rec I1;
rec I1p;
rec Q1p;
rec Phase1;
rec Phase;
rec DeltaPhase;
rec DeltaPhase1;
rec InstPeriod1;
rec InstPeriod;
def CorrectionFactor;

if barNumber() <= 5
then {
Period = 0;
Smooth = 0;
Detrender = 0;
CorrectionFactor = 0;
Q1 = 0;
I1 = 0;
Q1p = 0;
I1p = 0;
Phase = 0;
Phase1 = 0;
DeltaPhase1 = 0;
DeltaPhase = 0;
InstPeriod = 0;
InstPeriod1 = 0;
} else {
CorrectionFactor = 0.075 * Period[1] + 0.54;

# Smooth and detrend my smoothed signal:
Smooth = WMA_Smooth(Price);
Detrender = ( 0.0962 * Smooth
+ 0.5769 * Smooth[2]
- 0.5769 * Smooth[4]
- 0.0962 * Smooth[6] ) * CorrectionFactor;

# Compute Quadrature and Phase of Detrended signal:
Q1p = ( 0.0962 * Detrender
+ 0.5769 * Detrender[2]
- 0.5769 * Detrender[4]
- 0.0962 * Detrender[6] ) * CorrectionFactor;
I1p = Detrender[3];

# Smooth out Quadrature and Phase:
I1 = 0.15 * I1p + 0.85 * I1p[1];
Q1 = 0.15 * Q1p + 0.85 * Q1p[1];

# Determine Phase
if I1 != 0 then {
# Normally, ATAN gives results from -pi/2 to pi/2.
# We need to map this to circular coordinates 0 to 2pi

if Q1 >= 0 and I1 > 0 then { # Quarant 1
Phase1 = ATan(absValue(Q1/I1));
} else if Q1 >= 0 and I1 < 0 then { # Quadrant 2
Phase1 = Double.PI - ATan(absValue(Q1/I1));
} else if Q1 < 0 and I1 < 0 then { # Quadrant 3
Phase1 = Double.PI + ATan(absValue(Q1/I1));
} else { # Quadrant 4
Phase1 = 2*Double.PI - ATan(absValue(Q1/I1));
}
} else if Q1 > 0 then { # I1 == 0, Q1 is positive
Phase1 = Double.PI/2;
} else if Q1 < 0 then { # I1 == 0, Q1 is negative
Phase1 = 3*Double.PI/2;
} else { # I1 and Q1 == 0
Phase1 = 0;
}

# Convert phase to degrees
Phase = Phase1 * 180 / Double.PI;

if Phase[1] < 90 and Phase > 270 then {
# This occurs when there is a big jump from 360-0
DeltaPhase1 = 360 + Phase[1] - Phase;
} else {
DeltaPhase1 = Phase[1] - Phase;
}

# Limit our delta phases between 7 and 60
if DeltaPhase1 < 7
then {
DeltaPhase = 7;
} else if DeltaPhase1 > 60 then {
DeltaPhase = 60;
} else {
DeltaPhase = DeltaPhase1;
}

# Determine Instantaneous period:
InstPeriod1 =
-1*(fold i=0 to 40 with v=0 do
if v < 0 then
v
else if v > 360 then
-i
else
v + getValue(DeltaPhase, i, 41)
);

if InstPeriod1 <= 0 then {
InstPeriod = InstPeriod[1];
} else {
InstPeriod = InstPeriod1;
}

Period = 0.25*InstPeriod + 0.75*Period[1];
}
plot DC = period;
}

script Ehler_MAMA {
input price = hl2;
input FastLimit = 0.5;
input SlowLimit = 0.05;


rec Period;
rec Period_raw;
rec Period_cap;
rec Period_lim;

rec Smooth;
rec Detrender;
rec I1;
rec Q1;
rec jI;
rec jQ;
rec I2;
rec Q2;
rec I2_raw;
rec Q2_raw;

rec Phase;
rec DeltaPhase;
rec DeltaPhase_raw;
rec alpha;
rec alpha_raw;

rec Re;
rec Im;
rec Re_raw;
rec Im_raw;

rec SmoothPeriod;
rec vmama;
rec vfama;

def CorrectionFactor = Phase_Accumulation(price).CorrectionFactor;

if barNumber() <= 5
then {
Smooth = 0;
Detrender = 0;

Period = 0;
Period_raw = 0;
Period_cap = 0;
Period_lim = 0;
I1 = 0;
Q1 = 0;
I2 = 0;
Q2 = 0;
jI = 0;
jQ = 0;
I2_raw = 0;
Q2_raw = 0;
Re = 0;
Im = 0;
Re_raw = 0;
Im_raw = 0;
SmoothPeriod = 0;
Phase = 0;
DeltaPhase = 0;
DeltaPhase_raw = 0;
alpha = 0;
alpha_raw = 0;
vmama = 0;
vfama = 0;
} else {
# Smooth and detrend my smoothed signal:
Smooth = WMA_Smooth(Price);
Detrender = ( 0.0962 * Smooth
+ 0.5769 * Smooth[2]
- 0.5769 * Smooth[4]
- 0.0962 * Smooth[6] ) * CorrectionFactor;

Q1 = ( 0.0962 * Detrender
+ 0.5769 * Detrender[2]
- 0.5769 * Detrender[4]
- 0.0962 * Detrender[6] ) * CorrectionFactor;
I1 = Detrender[3];

jI = ( 0.0962 * I1
+ 0.5769 * I1[2]
- 0.5769 * I1[4]
- 0.0962 * I1[6] ) * CorrectionFactor;

jQ = ( 0.0962 * Q1
+ 0.5769 * Q1[2]
- 0.5769 * Q1[4]
- 0.0962 * Q1[6] ) * CorrectionFactor;

# This is the complex conjugate
I2_raw = I1 - jQ;
Q2_raw = Q1 + jI;

I2 = 0.2*I2_raw + 0.8*I2_raw[1];
Q2 = 0.2*Q2_raw + 0.8*Q2_raw[1];

Re_raw = I2*I2[1] + Q2*Q2[1];
Im_raw = I2*Q2[1] - Q2*I2[1];

Re = 0.2*Re_raw + 0.8*Re_raw[1];
Im = 0.2*Im_raw + 0.8*Im_raw[1];

# Compute the phase
if Re != 0 and Im != 0 then {
Period_raw = 2*double.PI / atan(Im/Re);
} else {
Period_raw = 0;
}

if Period_raw > 1.5*Period_raw[1] then {
Period_cap = 1.5*Period_raw[1];
} else if Period_raw < 0.67 * Period_raw[1] {
Period_cap = 0.67 * Period_raw[1];
} else {
Period_cap = Period_raw;
}

if Period_cap < 6 then {
Period_lim = 6;
} else if Period_cap > 50 then {
Period_lim = 50;
} else {
Period_lim = Period_cap;
}

Period = 0.2*Period_lim + 0.8*Period_lim[1];
SmoothPeriod = 0.33*Period + 0.67*SmoothPeriod[1];

if I1 != 0 then {
Phase = ATan(Q1 / I1);
} else if Q1 > 0 then { # Quadrant 1:
Phase = Double.Pi/2;
} else if Q1 < 0 then { # Quadrant 4:
Phase = -Double.Pi/2;
} else { # Both numerator and denominator are 0.
Phase = 0;
}

DeltaPhase_raw = Phase[1] - Phase;
If DeltaPhase_raw < 1 then {
DeltaPhase = 1;
} else {
DeltaPhase = DeltaPhase_raw;
}

alpha_raw = FastLimit / DeltaPhase;
If alpha_raw < SlowLimit then {
alpha = SlowLimit;
} else {
alpha = alpha_raw;
}
vmama = alpha*Price + (1 - alpha)*vmama[1];
vfama = 0.5*alpha*vmama + (1 - 0.5*alpha)*vfama[1];
}

plot MAMA = vmama;
plot FAMA = vfama;
}

declare upper;
input price = hl2;
input FastLimit = 0.5;
input SlowLimit = 0.05;

plot MAMA = Ehler_MAMA(price, FastLimit, SlowLimit).MAMA;
plot FAMA = Ehler_MAMA(price, FastLimit, SlowLimit).FAMA;

plot Crossing = crosses((MAMA < FAMA), yes);
Crossing.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);

plot Crossing1 = crosses((MAMA > FAMA), yes);
Crossing1.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);

AddChartLabel(yes, concat("MAMA: ", concat("",
If MAMA > FAMA then "Bull" else "Bear")),

If MAMA > FAMA then color.green else color.red);

Reply With Quote
 
  #2 (permalink)
Site Administrator
Manta, Ecuador
 
Futures Experience: Advanced
Platform: My own custom solution
Favorite Futures: E-mini ES S&P 500
 
Big Mike's Avatar
 
Posts: 46,240 since Jun 2009
Thanks: 29,352 given, 83,229 received

Tip

Please wrap code in the [code]put code here[/code] tags. This will prevent bad forum formatting and also make it easier to read the thread.



Mike

Due to time constraints, please do not PM me if your question can be resolved or answered on the forum.

Need help?
1) Stop changing things. No new indicators, charts, or methods. Be consistent with what is in front of you first.
2) Start a journal and post to it daily with the trades you made to show your strengths and weaknesses.
3) Set goals for yourself to reach daily. Make them about how you trade, not how much money you make.
4) Accept responsibility for your actions. Stop looking elsewhere to explain away poor performance.
5) Where to start as a trader? Watch this webinar and read this thread for hundreds of questions and answers.
6)
Help using the forum? Watch this video to learn general tips on using the site.

If you want
to support our community, become an Elite Member.

Reply With Quote
 
  #3 (permalink)
Trading Apprentice
east brunswick
 
Futures Experience: Master
Platform: TOS, Tradestation
Favorite Futures: CL, ES, GC, 6E, 6A, 6J, 6B
 
Posts: 3 since Dec 2010
Thanks: 0 given, 3 received

MAMA P&L


I am getting a bit closer. I can calculate a profit here after hardwiring an entry price, but did not yet figure out how to pick up the entry price nor keep a running tally of P&L nor get it to automate long or short:

 
Code
# hint: <b>Ehler's Mesa Adaptive Moving Average</b> using Ray's clean version
# of the homodyne discriminator. 
#

# MIT License
# Copyright (c) <2010> <Radford Juang>
#
#Permission is hereby granted, free of charge, to any person obtaining a copy
#of this software and associated documentation files (the "Software"), to deal
#in the Software without restriction, including without limitation the rights
#to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
#copies of the Software, and to permit persons to whom the Software is
#furnished to do so, subject to the following conditions:
#
#The above copyright notice and this permission notice shall be included in
#all copies or substantial portions of the Software.
#
#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
#IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
#FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
#AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
#LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
#OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
#THE SOFTWARE.
#

script WMA_Smooth {
    input price = hl2;
    plot smooth = (4 * price 
                 + 3 * price[1] 
                 + 2 * price[2]
                 +   price[3]) / 10;
}

script Phase_Accumulation {
# This is Ehler's Phase Accumulation code. It has a full cycle delay. 
# However, it computes the correction factor to a very high degree.
#
    input price = hl2;

    rec Smooth;  
    rec Detrender;
    rec Period;
    rec Q1;
    rec I1; 
    rec I1p;
    rec Q1p;
    rec Phase1;
    rec Phase;
    rec DeltaPhase;
    rec DeltaPhase1;
    rec InstPeriod1;
    rec InstPeriod;
    def CorrectionFactor;
        
    if barNumber() <= 5
    then {
        Period = 0;
        Smooth = 0;
        Detrender = 0;
        CorrectionFactor = 0;
        Q1 = 0;
        I1 = 0;
        Q1p = 0;
        I1p = 0;
        Phase = 0;
        Phase1 = 0;
        DeltaPhase1 = 0;
        DeltaPhase = 0;
        InstPeriod = 0;
        InstPeriod1 = 0;
    } else {
        CorrectionFactor = 0.075 * Period[1] + 0.54;
    
        # Smooth and detrend my smoothed signal:
        Smooth = WMA_Smooth(Price);
        Detrender = ( 0.0962 * Smooth 
                        + 0.5769 * Smooth[2]
                        - 0.5769 * Smooth[4]
                        - 0.0962 * Smooth[6] ) * CorrectionFactor;

        # Compute Quadrature and Phase of Detrended signal:
        Q1p =        ( 0.0962 * Detrender 
                        + 0.5769 * Detrender[2]
                        - 0.5769 * Detrender[4]
                        - 0.0962 * Detrender[6] ) * CorrectionFactor;
        I1p = Detrender[3];

        # Smooth out Quadrature and Phase:
        I1 = 0.15 * I1p + 0.85 * I1p[1];
        Q1 = 0.15 * Q1p + 0.85 * Q1p[1];
        
        # Determine Phase
        if I1 != 0 then {
            # Normally, ATAN gives results from -pi/2 to pi/2. 
            # We need to map this to circular coordinates 0 to 2pi
            
            if Q1 >= 0 and I1 > 0 then { # Quarant 1
                Phase1 = ATan(absValue(Q1/I1));
            } else if Q1 >= 0 and I1 < 0 then { # Quadrant 2
                Phase1 = Double.PI - ATan(absValue(Q1/I1));
            } else if Q1 < 0 and I1 < 0 then { # Quadrant 3
                Phase1 = Double.PI + ATan(absValue(Q1/I1));
            } else { # Quadrant 4
                Phase1 = 2*Double.PI - ATan(absValue(Q1/I1));
            }
        } else if Q1 > 0 then {  # I1 == 0, Q1 is positive
            Phase1 = Double.PI/2;
        } else if Q1 < 0 then {  # I1 == 0, Q1 is negative
            Phase1 = 3*Double.PI/2;
        } else { # I1 and Q1 == 0
            Phase1 = 0;
        }

        # Convert phase to degrees
        Phase = Phase1 * 180 / Double.PI;

        if Phase[1] < 90 and Phase > 270 then { 
            # This occurs when there is a big jump from 360-0
            DeltaPhase1 = 360 + Phase[1] - Phase;
        } else {
            DeltaPhase1 = Phase[1] - Phase;
        }

        # Limit our delta phases between 7 and 60            
        if DeltaPhase1 < 7
        then {
            DeltaPhase = 7;
        } else if DeltaPhase1 > 60 then {
            DeltaPhase = 60;
        } else {
            DeltaPhase = DeltaPhase1;
        }

        # Determine Instantaneous period:            
        InstPeriod1 = 
            -1*(fold i=0 to 40 with v=0 do 
                if v < 0 then
                    v
                else if v > 360 then 
                    -i
                else 
                    v + getValue(DeltaPhase, i, 41)
                );

        if InstPeriod1 <= 0 then {
            InstPeriod = InstPeriod[1];
        } else {
            InstPeriod = InstPeriod1;
        }
    
        Period = 0.25*InstPeriod + 0.75*Period[1];
    }
    plot DC = period;
}

script Ehler_MAMA {
    input price = hl2;
    input FastLimit = 0.5;
    input SlowLimit = 0.05;


    rec Period;
    rec Period_raw;
    rec Period_cap;
    rec Period_lim;

    rec Smooth;  
    rec Detrender;
    rec I1; 
    rec Q1;
    rec jI;
    rec jQ;
    rec I2;
    rec Q2;
    rec I2_raw;
    rec Q2_raw;

    rec Phase;
    rec DeltaPhase;
    rec DeltaPhase_raw;
    rec alpha;
    rec alpha_raw;

    rec Re;
    rec Im;
    rec Re_raw;
    rec Im_raw;

    rec SmoothPeriod;
    rec vmama;
    rec vfama;

    def CorrectionFactor = Phase_Accumulation(price).CorrectionFactor;
          
    if barNumber() <= 5
    then {
        Smooth = 0;
        Detrender = 0;

        Period = 0;
        Period_raw = 0;
        Period_cap = 0;
        Period_lim = 0;
        I1 = 0;
        Q1 = 0;
        I2 = 0;
        Q2 = 0;
        jI = 0;
        jQ = 0;
        I2_raw = 0;
        Q2_raw = 0;
        Re = 0;
        Im = 0;
        Re_raw = 0;
        Im_raw = 0;
        SmoothPeriod = 0;
        Phase = 0;
        DeltaPhase = 0;
        DeltaPhase_raw = 0;
        alpha = 0;
        alpha_raw = 0;
        vmama = 0;
        vfama = 0;
    } else {    
        # Smooth and detrend my smoothed signal:
        Smooth = WMA_Smooth(Price);
        Detrender = ( 0.0962 * Smooth 
                    + 0.5769 * Smooth[2]
                    - 0.5769 * Smooth[4]
                    - 0.0962 * Smooth[6] ) * CorrectionFactor;

        Q1 = ( 0.0962 * Detrender 
                    + 0.5769 * Detrender[2]
                    - 0.5769 * Detrender[4]
                    - 0.0962 * Detrender[6] ) * CorrectionFactor;
        I1 = Detrender[3];
        
        jI = ( 0.0962 * I1 
                    + 0.5769 * I1[2]
                    - 0.5769 * I1[4]
                    - 0.0962 * I1[6] ) * CorrectionFactor;

        jQ = ( 0.0962 * Q1 
                    + 0.5769 * Q1[2]
                    - 0.5769 * Q1[4]
                    - 0.0962 * Q1[6] ) * CorrectionFactor;
        
        # This is the complex conjugate
        I2_raw = I1 - jQ;
        Q2_raw = Q1 + jI;
        
        I2 = 0.2*I2_raw + 0.8*I2_raw[1];
        Q2 = 0.2*Q2_raw + 0.8*Q2_raw[1];

        Re_raw = I2*I2[1] + Q2*Q2[1]; 
        Im_raw = I2*Q2[1] - Q2*I2[1]; 

        Re = 0.2*Re_raw + 0.8*Re_raw[1];
        Im = 0.2*Im_raw + 0.8*Im_raw[1];

        # Compute the phase
        if Re != 0 and Im != 0 then {
            Period_raw = 2*double.PI / atan(Im/Re);
        } else {
            Period_raw = 0;
        }

        if Period_raw > 1.5*Period_raw[1] then {
            Period_cap = 1.5*Period_raw[1];
        } else if Period_raw < 0.67 * Period_raw[1] {
            Period_cap = 0.67 * Period_raw[1];
        } else {
            Period_cap = Period_raw;
        }

        if Period_cap < 6 then { 
            Period_lim = 6;
        } else if Period_cap > 50 then {
            Period_lim = 50;
        } else {
            Period_lim = Period_cap;
        }
        
        Period = 0.2*Period_lim + 0.8*Period_lim[1];
        SmoothPeriod = 0.33*Period + 0.67*SmoothPeriod[1];

        if I1 != 0 then {  
            Phase = ATan(Q1 / I1);
        } else if Q1 > 0 then {  # Quadrant 1:
            Phase = Double.Pi/2;
        } else if Q1 < 0 then {  # Quadrant 4:
            Phase = -Double.Pi/2;
        } else { # Both numerator and denominator are 0. 
            Phase = 0;
        }
        
        DeltaPhase_raw = Phase[1] - Phase;
        If DeltaPhase_raw < 1 then {
          DeltaPhase = 1;
        } else {
          DeltaPhase = DeltaPhase_raw;
        }

        alpha_raw = FastLimit / DeltaPhase;
        If alpha_raw < SlowLimit then {
            alpha = SlowLimit;
        } else {
            alpha = alpha_raw;
        }
       vmama = alpha*Price + (1 - alpha)*vmama[1];
       vfama = 0.5*alpha*vmama + (1 - 0.5*alpha)*vfama[1];
    }

    plot MAMA = vmama;
    plot FAMA = vfama;
}

declare upper;
input price = hl2;
input FastLimit = 0.5;
input SlowLimit = 0.05;

plot MAMA = Ehler_MAMA(price, FastLimit, SlowLimit).MAMA;
plot FAMA = Ehler_MAMA(price, FastLimit, SlowLimit).FAMA;

plot Crossing = crosses((MAMA < FAMA), yes);
Crossing.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);

plot Crossing1 = crosses((MAMA > FAMA), yes);
Crossing1.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);

AddChartLabel(yes, concat("MAMA: ",  concat("",  
If MAMA > FAMA then "Bull" else "Bear")), 

If MAMA > FAMA then color.green else  color.red);

# Entry price calculation and storage
#rec entry_price = if crosses((MAMA < FAMA), yes) 
#then close 
#else entry_price[1];
input StartPrice = 1200;

# Exit price calculation and storage
rec exit_price = if crosses((MAMA > FAMA), yes) 
then close 
else exit_price[1];
def curPrice = exit_price;

#################################
# Study: VicEquity

# Date: Dec 1 2010
# Purpose: to display current P/L equity position on chart window.
#################################

# User Inputs:
input TransactionType = {default Long, "Short"}; # Define if we are going long or short
input ContractSize = 1; # number of contracts bought or sold
input Equity = {default "/ES", "/6A", "/TF", "/YM", "/NQ", "/6E", "/GC", "/CL"}; # drop down list of several symbols

# different futures have different multipliers... let's hard code it for one time...great if it can be pulled from some library/repository
def FuturesMultiplier;
def tickSize;

switch (Equity) {
case "/ES": # S & P E-mini
FuturesMultiplier = 12.5;
tickSize = .25;

case "/6A": # Aussie
FuturesMultiplier = 125000;
tickSize = 1; # I have no idea, someone else can look this up
default:
FuturesMultiplier = 1;
tickSize = 1;
}

def ProfitLoss;
switch (TransactionType) {
case "Long":
ProfitLoss = (CurPrice - StartPrice)/tickSize * ContractSize * FuturesMultiplier;
case "Short":
ProfitLoss = (StartPrice - CurPrice)/tickSize * ContractSize * FuturesMultiplier;

}

# Label on top left corner
# paste a label on upper chart showing the P/L for the contract..
AddChartLabel(yes,
concat(getSymbolPart(), concat(TransactionType, concat(" : $", ProfitLoss))),
if ProfitLoss >= 0 then color.green else color.red );

Reply With Quote
The following 2 users say Thank You to ebtrader for this post:

Reply



futures io > > > > > MAMA with Buy Sell Signals and P&L

Thread Tools Search this Thread
Search this Thread:

Advanced Search



Upcoming Webinars and Events (4:30PM ET unless noted)

Jigsaw Trading: TBA

Elite only

FuturesTrader71: TBA

Elite only

NinjaTrader: TBA

Jan 18

RandBots: TBA

Jan 23

GFF Brokers & CME Group: Futures & Bitcoin

Elite only

Adam Grimes: TBA

Elite only

Ran Aroussi: TBA

Elite only
     

Similar Threads
Thread Thread Starter Forum Replies Last Post
Buy Stops / Sell Stop and ATM Strategies Baertrader NinjaTrader 9 August 21st, 2011 04:45 PM
Is it possible to show Buy/Sell strength in NT6.5? steveg NinjaTrader 1 March 15th, 2011 01:40 PM
[NinjaTrader]    buy sell chart jamfutures Platforms and Indicators 10 July 14th, 2010 08:36 PM
MA cross Buy/Sell Strategy - need help SPMCC NinjaTrader Programming 11 January 31st, 2010 07:16 PM
Buy/Sell in an indicator Mindset NinjaTrader Programming 11 October 8th, 2009 10:16 AM


All times are GMT -4. The time now is 10:49 PM.

Copyright © 2017 by futures io, s.a., Av Ricardo J. Alfaro, Century Tower, Panama, +507 833-9432, info@futures.io
All information is for educational use only and is not investment advice.
There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
no new posts
Page generated 2017-12-13 in 0.11 seconds with 19 queries on phoenix via your IP 54.226.113.250