Solved

Deals interval

Posted on 2011-03-18
8
296 Views
Last Modified: 2012-08-13
This class send signals to open positions after comparing with some parameters.
private static DecisionCenter_EURUSD_S instance =
        new DecisionCenter_EURUSD_S();

    public static DecisionCenter_EURUSD_S getInstance() {
        return instance;
    }

    public void sellControl(int sell) {
        if (sell == 1) {
            mflag0s = 1;
        } else {
            mflag0s = 0;
        }
        System.out.println(" DC_S EUR/USD  sell =  " + sell);
        System.out.println(" DC_S EUR/USD   mflag0s =  " + mflag0s);

        if (mflag0s == 1) {
            sell_mflag0s = "Open";
        } else if (mflag0s == 0) {
            sell_mflag0s = "Close";
        }

        FlagControl.getInstance().setTradeSell_EURUSD(sell_mflag0s);
    }

    public void bControl(int borderS) {
        if (borderS == 1) {
            mbc = 1;
        } else {
            mbc = 0;
        }
    }

    public void positionControl(int position) {
        if (position == 1) {
            mopc = 1;
        } else {
            mopc = 0;
        }
    }

    public void decisionCenter_EURUSD_S(boolean bl0) throws Exception {

        try {

            if (bl0 == false && mflag0s == 1 && mbc == 1 && mopc == 1)

                side = SideFactory.SELL;

            System.out.println("    side  " + side);

            AlgoTradeMarket_EURUSD.getInstance(null).algoTradeMarket(side);

        } catch (Exception ex) {
            Logger.getLogger(DecisionCenter_EURUSD_S.class.getName()).log(Level.SEVERE,
                                                                          null,
                                                                          ex);
        }
    }
}

Open in new window

but in view that changing parameters takes some time, method
public void decisionCenter_EURUSD_S(boolean bl0)
continue to send signals for opening positions until it get new changed value from one of parameters.
My question is how to limit opening new positions by setting some restrictions by time interval which will be long enough to get new values, let's say 1000L.
If it's need some clarifications, please ask.
Thank you
0
Comment
Question by:gbcbr
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
8 Comments
 
LVL 47

Expert Comment

by:for_yan
ID: 35171100
Well, it is true, that needs some clarification:  it is not quite clear
what is your ultimate goal and what prevents you from monitoring the time when you receive
signals and make necessary decisions based on the time interval.
0
 

Author Comment

by:gbcbr
ID: 35171237
The problem is that signals bl0 arrive with fixed 1 sec interval, because it's also artificially generated data.
But, most probably, the time taken by inserting and deleting positions takes more than 1 sec, when next value bl0 come it's read still old value of open positions from array list.
My opinion that it's easiest way just to find proper time interval during which completed changes into array list and restrict
this action:
AlgoTradeMarket_EURUSD.getInstance(null).algoTradeMarket(side);
during this period.
Most probably it has to be another array list in which we record time of deals and compare them and if interval to previous deal less then n it ignored.
ArrayList al_time = new ArrayList
time = new java.util.Date());
al_time.add(time)
up to here I understand, please advice how to compare next time to previous and put limit 2 sec.

so
if (previous (time) older than current(time) more than 2 seconds) {
AlgoTradeMarket_EURUSD.getInstance(null).algoTradeMarket(side);
}
and after delete old value and leave only the last
0
 
LVL 47

Expert Comment

by:for_yan
ID: 35171835
If d1 and d2 are two java.util.Date objects then their difference in milliseconds will be d1.getTime() - d2.getTime(), so
if((d2.getTime() - d1.getTime()) > 2000) will mean that d1 is older by more than 2 second
then you assign the new value to the old,
and you have everything you need.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:gbcbr
ID: 35171860
Ok, but how to define  d1.
 
try {

            if (bl0 == false && mflag0s == 1 && mbc == 1 && mopc == 1)

                side = SideFactory.SELL;

            System.out.println("    side  " + side);

            d1 = ?????????

            d2 = new java.util.Date());
            al_time.add(d2)

            if((d2.getTime() - d1.getTime()) > 2000) {

            AlgoTradeMarket_EURUSD.getInstance(null).algoTradeMarket(side);
            
             }

Open in new window

0
 
LVL 47

Accepted Solution

by:
for_yan earned 500 total points
ID: 35171887
Again you declare

 java.util.Date arriveDate;

as a class variable.

Then in the place where your signals arrive (say, inside some method), you'll
say

java.util.Date d2 = new java.util.Date();
if(arriveDate == null){
arriveDate = d2;  // this will take care of your first signal, where you don't have any previous signal; do you want also  to call your AlgoTrademethod first time - you decide
}else
{
            if((d2.getTime() - arriveDate.getTime()) > 2000) {

         arriveDate = d2;
            AlgoTradeMarket_EURUSD.getInstance(null).algoTradeMarket(side);
           
           
             }
}

0
 
LVL 47

Expert Comment

by:for_yan
ID: 35171892
You should actually use "2000L" instaed of "2000", as getTime() returns long value
0
 

Author Comment

by:gbcbr
ID: 35171909
Excellent, hope it will work.
We can check this only on Monday.
Thank you for help.
0
 
LVL 47

Expert Comment

by:for_yan
ID: 35171937

You are always welcome.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
String array comparison 4 57
Tagging and Merging on Branch 1 68
Read CLOB data from Oracle using JAVA 3 42
Setup Eclipse for Andriod development 2 19
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
Suggested Courses

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question